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?
You need to add this dependency in your build.gradle(app)
compile 'com.firebase:firebase-client-android:2.5.0'
Now with New Android Studio ,Its so easy to add Firebase to your Project.
Below are Simple Steps-
1. On Android Studio’s Tools menu, you’ll see an entry that reads Firebase.
2. Select this, and a Firebase Assistant pane will open to the side of your code editor:
3. On this pane, click the arrow beside ‘Authentication’, and you’ll see a step through for ‘Email and Password Authentication’.
4. Click the ‘Connect to Firebase’ button.
Your browser will open with a ‘Request for Permissions’ dialog:
5.Click ‘Allow’, and then after a ‘Success!’ screen, you’ll be given a dialog with which to connect to Firebase.
6.You will see Connected .Its Done !
For more on Firebase refer here.
You can open and use the Assistant window in Android Studio by following these steps:
Click Tools > Firebase to open the Assistant window. And it will guide you for sync firebase and your project.
Make sure you fulfill the following prerequisites before adding firebase to your project.
For working with Firebase you should install Android Studio 1.5 or higher.
Download the latest Google Play services SDK from through Android SDK Manager.
The device should be running Android 2.3 (Gingerbread) or newer, and Google Play services 9.2.0 or newer.
I find out all this after hours of struggle, so thought of sharing with others.
Source: Adding Firebase to your Android App
Invalidating cache didn't work for me. But deleting .idea/libraries worked like magic.
More info here: https://stackoverflow.com/a/50129167/971972
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'
}
}
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
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
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
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).
Related
I have tried to integrate Stripe with my project. I have gone through the integration guide from https://stripe.com/docs/mobile/android. And I keep receiving an error Could not resolve com.stripe:stripe-android:6.1.2.
I have put into my build.gradle file Could not resolve com.stripe:stripe-android:8.0.0. Additionally, I have found the GitHub project that version varies from the one in the guide and I have tried it. The version number in the GitHub project is 8.0.0.
Full error log:
The short version of my dependencies in gradle:
dependencies {
...
implementation 'com.stripe:stripe-android:8.0.0'
...
}
Is there any additional maven repo or something that I should add to the gradle to be able to add this dependency to the project?
You might have enabled offline work for gradle,
Uncheck the box and sync the project again . It should fix the problem.
I want to completely disconnect my app from Firebase. This question has been asked several times (e.g here). Most of the answers focus on disconnecting an app from Firebase within the Firebase console and not within Android studio.
After disconnecting my app from the Firebase console. Everytime I try to reconnect the app to another Firebase project, an error balloon pops up stating that the app is already part of a Firebase project. I know this behaviour occurs because some files from the old Firebase project are still present. How do I get rid of them?
Try these steps to remove Fire-base from Android Studio project.
Delete google-services.json file from the Project (Find the file by Project view)
Remove dependencies from Project-level build.gradle (/build.gradle)
buildscript {
dependencies {
// Remove this line
classpath 'com.google.gms:google-services:4.2.0'
}
}
Remove all the Fire-base related dependencies from the project App-level build.gradle (//build.gradle) file
dependencies {
// Remove this line
implementation 'com.google.firebase:firebase-core:17.0.0'
}
Remove the line below from the bottom of the App-level build.gradle (//build.gradle) file
apply plugin: 'com.google.gms.google-services'
Restart Android Studio
Try this, On the project level, delete the google-services.json file
and then sync the project
You should undo all the steps that you are instructed to perform in the manual integration. So, remove all Firebase dependencies from build.gradle, remove the Google Services plugin from the bottom of build.gradle, and remove the google-services.json file.
Try shutting down the Firebase project created with the package name of the connected application; although it doesn't delete at the same time and is scheduled for later. Don't link your android app with any other firebase app till the previous connected app has been deleted completely.
Do the following (If you want to Switch Firebase Data Sources):
In Android Studio, Go to Tools>Firebase, Choose any of the options such as Real time-database
Click Connect to Firebase.
You will get a warning that the App is already connected to Firebase.
Click okay.
Android Studio will open a Firebase console on a browser.
Choose the Firebase App you want to you want to connect to.
Done.
On the main menu, select app ,select ,google-services.json' and then right click then delete
I am new to Android, and I was trying to Add GoogleSignin in my blank app.
I am following this tutorial from YouTube: https://www.youtube.com/watch?v=2PIaGpJMCNs, which says to add Gradle dependencies as shown in "Google's official documentation". But I don't see any such dependencies given in the official documentation.
I feel I am stuck in the process. Is it that the documents shown in the video are deprecated and now we don't need to add Gradle dependencies for Google SignIn?
I have performed the following steps:
1) Created a project in Android Studio
2) Added internet permission in manifest
3) Created a Project in Google Developer Console
4) Generated the SHA Key and added to the official documentation form
5) Generated the credential.json file and pasted it into the app folder of my Android Studio App
6) Installed Google play Services
7) Now the tutorial says to add Gradle dependencies in my project as provided in the "Official Google Documentation", but, as mentioned above, I could not find any such thing. I can't find anywhere in the page which tells me anything about adding Gradle Dependencies
To implement GoogleSignIn follow the following simple steps:
Add implementation 'com.google.android.gms:play-services-auth:15.0.1' in your app level build.gradle file.
Configure your project in Google console here
Follow further steps here
Am new to cordova, I have created a cordova app and run successfully, now I need to integrate a push notification in it. So i gone with google Firebase, i have created all the dependencies for firebase and downloaded google.services.json . And i have added listener in index.js file (refered this link) also, no problem upto this. In the firebase Document, asked to add these lines at app level build grade
compile 'com.google.firebase:firebase-core:11.8.0'
apply plugin: 'com.google.gms.google-services'
and this at buildscript classpath 'com.google.gms:google-services:3.0.0'
After adding this am using command cordova build android , it throws error. Am not sure what is wrong
Note :
Also tried without adding the above line, in that case, build gets success but the notification is not working.
You can refer to the official phonegap plugin here. This would give you a fair idea on how to do or alternatively if it meets your use case you can directly use it.
Cordova is a free version of phone-gap so compatibility will not be an issue.
I finally managed to get google app invites working in my app. I enabled them on the developer console and followed this guide. The following steps were giving me problems:
Add the dependency to your project's top-level build.gradle:
classpath 'com.google.gms:google-services:1.3.0-beta1'
Add the plugin to your app-level build.gradle:
apply plugin: 'com.google.gms.google-services'
Copy the google-services.json file you just downloaded into the app/ or mobile/ directory of your Android Studio project.
By adding that classpath I had to use jcenter as my repository, as this package isn't available at mavenCentral. However, even if I built the project with jcenter as a repository, the gradle build failed with an empty error message. I tried to debug the problem but the stacktrace for the crash was enormous.
My solution was to simply ignore these steps. The app invites are working flawlessly since then.
With this in mind, here goes my question. Why were all these steps listed on the official google guide if they are not necessary? Am I missing something here?
When I started official sample for Invite API yesterday, I had problem but just because of version of google-services (1st step -> add the dependency of your project's top-level build.gradle), so I have to change it to the latest version:
classpath 'com.android.tools.build:gradle:1.3.0-beta4'
classpath 'com.google.gms:google-services:1.3.0-beta4'
and this solves all problems. I don't understand your question, which step you exactly skipped of these 3 steps mentioned and made invite api functional?
Finally found the answer. The service was working on my prototype because it doesn't check for credentials on the test device. Once released to public, the keys are needed for the service to work correctly as Ituoke Ajanlekoko said in the comments.
Further information can be found at this topic:
What does google-services.json really do?