Reputation: 171
I'm currently upgrading an app to the new Firebase version. I followed the guide, included classpath 'com.google.gms:google-services:3.0.0'
in the dependencies of my project build.gradle as well as compile 'com.google.firebase:firebase-core:9.0.1'
among others in the dependencies of my module build.gradle and also apply plugin: 'com.google.gms.google-services'
at the end of that file.
I get a "cannot resolve symbol 'firebase'" in my imports i.e. import com.google.firebase.database.DatabaseReference;
. Those are not errors that appear when building, so this seems to be working, but they are visible in the code editor of Android Studio.
The imports worked just fine a couple of days ago (except for FirebaseAuth, which was under maintenance). I did not change anything about the code since then (except trying to upgrade to 9.0.2, which lead to the same result). The only thing I did was update some components of the Android SDK, but I can't remember which. The Android SDK as well as Google Repository and Google Play Services are of the newest version. Rebuilding, cleaning and invalidate caches / restart had no effect.
Any ideas how to fix this?
Upvotes: 17
Views: 64761
Reputation: 52494
You need the Firebase client library. Add this to your app gradle:
dependencies {
// Firebase
implementation 'com.firebase:firebase-client-android:2.5.2'
Replace 2.5.2 with the latest version (there is probably a new one out there since I posted this answer).
dependencies should be used in the latest gradle version (not compile).
Upvotes: 1
Reputation: 41
You can open and use the Assistant window in Android Studio by following these steps:
Upvotes: 4
Reputation: 1180
Invalidating cache didn't work for me. But deleting .idea/libraries
worked like magic.
More info here: https://stackoverflow.com/a/50129167/971972
Upvotes: 3
Reputation: 21
In the new SDK, it's no longer necessary to call Firebase.setAndroidContext() so you can remove it from your code.
In the new SDK, Firebase references are replaced by DatabaseReference and you use the FirebaseDatabase class to get an initial reference to your database. So you can get the database reference in your code as follows:
BEFORE Firebase rootRef = new Firebase("https://.firebaseio.com/"); AFTER DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
Note that your Database URL is automatically determined from the google-services.json file you downloaded, so you don't need to specify it. If you want to specify it though, you still can (which might be convenient for migration purposes):
BEFORE Firebase ref = new Firebase("https://.firebaseio.com/path/to/data"); AFTER DatabaseReference ref = FirebaseDatabase.getInstance() .getReferenceFromUrl("https://.firebaseio.com/path/to/data");
22
Upvotes: 2
Reputation: 70
After adding it in from the built in Firebase tool and also following the following a tutorial, the imports did not work on one of my classes so all you have to do is sync the gradle files
Tutorial I've used: https://www.androidtutorialpoint.com/firebase/firebase-cloud-messaging-tutorial/
Tools/Android/Sync Project with Gradle Files.
Works 100% now
Upvotes: 1
Reputation: 3372
To use the Firebase Messaging service you need to add the following dependencies to your app's build.gradle file:
compile 'com.google.firebase:firebase-messaging:9.4.0'
I had the same problem but thanks to this answer:
https://stackoverflow.com/a/39353961/4836759
Upvotes: 2
Reputation: 63
Add following in your gradle file under dependencies:
compile 'com.firebase:firebase-client-android:2.5.2'
If you are getting a build error complaining about duplicate files you can choose to exclude those files by adding the packagingOptions directive to your build.gradle file:
android {
...
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
Upvotes: 2
Reputation: 3673
Now with New Android Studio ,Its so easy to add Firebase to your Project.
Below are Simple Steps-
Your browser will open with a ‘Request for Permissions’ dialog:
For more on Firebase refer here.
Upvotes: 11
Reputation: 193
You need to add this dependency in your build.gradle(app)
compile 'com.firebase:firebase-client-android:2.5.0'
Upvotes: 16
Reputation: 332
Make sure you fulfill the following prerequisites before adding firebase to your project.
I find out all this after hours of struggle, so thought of sharing with others.
Source: Adding Firebase to your Android App
Upvotes: 3