Cannot resolve symbol default_web_client_id in Firebase's Android Codelab - android

I am trying to learn Firebase, so I went through the Android Codelab. The project they gave me however, had an error:
Cannot resolve symbol default_web_client_id
And I didn't know how to solve it, since I didn't know the value of default_web_client_id or what it is. It is in the onCreate() method:
SigninActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
mFirebaseAuth = FirebaseAuth.getInstance();
// Assign fields
mSignInButton = (SignInButton) findViewById(R.id.sign_in_button);
// Set click listeners
mSignInButton.setOnClickListener(this);
// Configure Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
}
I have no idea what it is, what's its value is, and why is it giving me this error. I haven't changed anything so far except for adding the google-services.json. I have added my SHA-1 and enabled Google in the console.

Sometimes there is issue while parsing google-services.json. I have reported this issue with to concerned team.
Meanwhile follow below step to fix this issue to get going further -
1) Open google-services.json file -> client -> oauth_client -> client_id
2) Copy this client ID and hardcode this .requestIdToken("your ID")
It would allow to request "IdToken" via GoogleSignInAccount post successful google login and to authorize your credential with firebase.
EDIT
Try deleting and recreating the project and re-importing new google-service.jsonin your Android project

A more generic solution would be to add the google-services.json into the app's root directory.
And add
apply plugin: 'com.google.gms.google-services at the end of build.gradle file.
Explanation
When the app builds the key value pair strings from google-services.json config file are then placed into the values.xml file to make them globally available for use from anywhere in your code. This saves us from hard coding the client_id in your code.
Note
Do not add the default_web_client_id with client_id as its value in the strings.xml in order to avoid the error of duplication, Error: Duplicate resourceslater on when you run your code.

google-services.json in ./app/ folder
Add in project-level build.gradle the following:
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:4.3.5'
}
In app-level build.gradle, apply the plugin:
apply plugin: 'com.google.gms.google-services'
This is the annoying thing I found. Upgrading it from 4.3.5 to anything higher than that makes Android Studio unable to detect the generated values.xml file.

After a time searching the "smart" fix without insert directly the client_id, following this answer from FirebaseUI project I just need to add the next line in app/build.gradle:
implementation 'com.firebaseui:firebase-ui-auth:4.3.2'

Apparently R.string.default_web_client_id is generated from the IDE build
I had assumed we are supposed to manually add it - time consuming mistake
https://developers.google.com/android/guides/google-services-plugin
The google-services plugin has two main functions: 1) Process the
google-services.json file and produce Android resources that can be
used in your application's code.
~~~~
The main result of the JSON processing is to produce two XML files
which you can reference as Android resources in your Java code.
And so - after successful build, if you search the IDE for string default_web_client_id , you will see one result is values.xml under the /generated folder, and there it has the values for your firebase config, like the example below.
Actually seeing that file, helped to clarify things here
<resources>
<string name="default_web_client_id" translatable="false">123.apps.googleusercontent.com</string>
<string name="firebase_database_url" translatable="false">https://123.firebaseio.com</string>
<string name="gcm_defaultSenderId" translatable="false">123</string>
<string name="google_api_key" translatable="false">123</string>
<string name="google_app_id" translatable="false">123</string>
</resources>

**The main issue with this right now for me was to make sure to download the json file from the same location. If the initial one came from the firebase console do not use the api console to get the file, and vise versa. The files are not the same **

I already have google-services.json downloaded and parsed, but still it doesn't find the string.
I noticed that my oauth_client had a key with client_type of 1 and that's all. In the Google API console, I only had an Android key.
So, you need to go to the API console and generate a Web Server key. Then, download your google-services.json again, and you'll have a oauth_client with a type of 3.
Now, the plugin will generate a string called default_web_client_id.

I had the same problem or similar,
Make sure that in your google-services.json you have:
...
"client": [
...
"oauth_client": [
...
{
"client_id": "YOUR WEB CLIENT ID",
"client_type": 3
}
...
For some reason the file downloaded from firebase console doesn't include it.
After adding the entry in the google-services.json file, everything started working as expected.
google-services-plugin documentation

In addition to the Dexto's Answer I would like to mention one more thing
In the JSON file you will get two kind of client id
One Which is having client_type value 1 and Another with the client_type value 3
Make sure you specified the client_id of client_type which has value of 3

classpath 'com.google.gms:google-services:4.1.0'
has a problem. instead use:
classpath 'com.google.gms:google-services:4.2.0'

Download your newest google-services.json. List of client_id is present for OAuth 2.0 client IDs in your Google Cloud Credentials.
Then check whether it contains client_id with "client_type" : 3 or not. If not, you need to create a new one:
Open the Credentials page in the API Console.
Click Create credentials -> OAuth cliend ID. Then chose type Web application.
Wait 2-3 minutes, refresh Firebase Console & download your google-services.json again. It should contain client_id with "client_type" : 3 now.
Clean & rebuild your project to apply new API config.
The client_id with "client_type" : 3 is usually inside oauth_client tag, not services or other_platform_oauth_client.
If you fall to this case & cannot build the project, try copy your client_id to oauth_client tag and rebuild again.
"client": [
...
"oauth_client": [
...
{
"client_id": "YOUR WEB CLIENT ID",
"client_type": 3
}
]
]

for my case:
The lib was old so I go get the last lib at: https://firebase.google.com/docs/auth/android/firebaseui
put in dependency:
implementation 'com.firebaseui:firebase-ui-auth:7.2.0'
along with what currently there
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:26.7.0')
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-auth-ktx'
and it is fixed

Try downloading your .json file again after changing the configuration in the Firebase console. Use this newer configuration file, not the old one.

Fixed after using this link to create my backend id to Google API.
https://developers.google.com/identity/sign-in/android/start-integrating#get_your_backend_servers_oauth_20_client_id
1- Open the Credentials page in the API Console.
2- The Web application type client ID is your backend server's OAuth 2.0 client ID.
After this, you can re-download your json file and android studio will automatically matching your string id.

I know it is late to answer but hope this will help someone in the future.
To access there is no need to hard code default_web_client_id in app.
To access default_web_client_id in Android App from google-services.json, we have to add SHA1 key under FireBase project Settings.
Go to Firebase Console > Open Project > Select App > Add Fingerprint.
After this copy generated google-services.json to project.
After this you will see the difference in json file as below:
Before :
"oauth_client": []
After :
"oauth_client": [
{
"client_id": "23........4-asdj...........................asda.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.abc.xyz",
"certificate_hash": "asjhdashhs"
}
},.....
This will solve your issue.

Generic solution for this is to apply google play services plugin at the end of build.gradle like this
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
buildFeatures {
dataBinding true
}
defaultConfig {
applicationId "xxxxxx"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// For Common Dimension
implementation 'com.intuit.sdp:sdp-android:1.0.5'
implementation 'com.intuit.ssp:ssp-android:1.0.5'
// Retrofit and Gson
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.6.1'
// Rx Java and Dagger
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'io.reactivex:rxjava:1.1.6'
implementation 'com.google.dagger:dagger:2.24'
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
compileOnly 'javax.annotation:jsr250-api:1.0'
compileOnly 'org.glassfish:javax.annotation:10.0-b28'
// Glide Image Loading
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
implementation 'com.android.support:design:30.0.0'
implementation 'com.android.support:recyclerview-v7:30.0.0'
implementation 'com.android.support:cardview-v7:30.0.0'
implementation 'com.android.support:multidex:1.0.3'
/*Jsoup*/
implementation 'org.jsoup:jsoup:1.9.1'
/*Firebase*/
implementation 'com.google.firebase:firebase-core:17.5.0'
implementation 'com.google.firebase:firebase-config:19.2.0'
implementation 'com.google.firebase:firebase-messaging:20.2.4'
implementation 'com.google.firebase:firebase-database:19.3.1'
implementation 'com.google.firebase:firebase-auth:19.3.2'
implementation 'com.firebaseui:firebase-ui-storage:6.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-analytics:17.5.0'
/*location and google map*/
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-places:17.0.0'
implementation 'com.google.android.gms:play-services-auth:18.1.0'
/*Circle Image View*/
implementation 'de.hdodenhof:circleimageview:3.0.1'
implementation 'com.github.ittianyu:BottomNavigationViewEx:2.0.4'
implementation "com.android.support:design:30.0.0"
implementation 'com.facebook.android:facebook-android-sdk:5.15.3'
}
apply plugin: 'com.google.gms.google-services'

in my case I forgot to add
id 'com.google.gms.google-services'
to the plugin of build.gradle(:app)

I also had the same issue, make sure "google-services.json" is in your app directory. Then simply rebuild the project from "Build -> Rebuild Project"
Since the string resource "default_web_client_id" is auto-generated, it will be resolved once you rebuild the project

Use BOM to use the compatible version of firebase.
In your module (app-level) Gradle file:
dependencies {
// ...
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:29.3.0')
// When using the BoM, you don't specify versions in Firebase library dependencies
// Declare the dependency for the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-analytics'
// Declare the dependencies for any other desired Firebase products
// For example, declare the dependencies for Firebase Authentication and Cloud Firestore
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-firestore'
}
Source: https://firebase.google.com/docs/android/setup?authuser=0&hl=en#add-sdks

Update your project level build.gradle file with the following code:
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
}}
allprojects {
repositories {
google()
jcenter()
maven { url "https://maven.google.com"}
}}
task clean(type: Delete) {
delete rootProject.buildDir }
More Details:answerdone.com

For me the problem was because I was using minSdkVersion 15, updating to 16 has solved my problem.

I have searched for it whole day, I already have pasted that json file inside App and rebuild many times, but the android studio still marks it as error in ide.
Solution: just run the project, ignore the error, it will work, it is an IDE bug.

implementation platform('com.google.firebase:firebase-bom:29.0.0')
implementation 'com.firebaseui:firebase-ui-auth:4.3.2'
Put these lines into build.gradle(projectName)

Related

How to fix 'java.lang.NoClassDefFoundError' in Android .aar project

I have an android .aar library built and I am trying to integrate it with one of the projects. When the app tries to open the initial screen of the .aar library where I have API call using retrofit. I am getting the below exception
java.lang.NoClassDefFoundError: Failed resolution
of:Lokhttp3/OkHttpClient$Builder;
I have not obfuscated or enabled pro-guard in my .aar project.
Below are my .aar Gradle dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
OK, this is a common issue. There are several ways to use an android library(aar) in other projects. For example:
By importing this aar as a module into your sample project by using
implementation project(':mylibrary').
By uploading your aar to a maven repository(artifactory, maven local, Jitpack, etc)
Pay attention to this:
If you are using number 1 above, so you will also have to
add(retrofit, okhttp3, etc) to your sample project with the same
version, because the aar by default doesn't include child
dependencies. That's why you are getting that exception
"java.lang.NoClassDefFoundError: Failed resolution of:
Lokhttp3/OkHttpClient$Builder'".
If you are using number 2 above, so you will have to make sure that your pom.xml file includes your child dependencies, because the server needs to download and have them available in your sample project.
What do I recommend?
I recommend developers to use MavenLocal(), it replicates a real scenario before publishing your aar to a public repository like Jitpack or whatever you want.
How can I do it?
Inside build.gradle of your library module:
apply plugin: 'maven-publish'
project.afterEvaluate {
publishing {
publications {
library(MavenPublication) {
setGroupId 'YOUR_GROUP_ID'
//You can either define these here or get them from project conf elsewhere
setArtifactId 'YOUR_ARTIFACT_ID'
version android.defaultConfig.versionName
artifact bundleReleaseAar //aar artifact you want to publish
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.implementation.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
}
Run assemble and publishToMavenLocal gradle tasks. And you'll see something like this:
In your Sample Project
allprojects {
repositories {
mavenLocal()
...
}
}
implementation '${YOUR_GROUP_ID}:${YOUR_ARTIFACT_ID}:${YOUR_VERSION}'
Let's assume you've built your .aar, and published it to a maven repository (artifactory, nexus, what have you) - e.g., "implementation 'com.mycompany:library:1.0#aar'". Any child dependencies need to be included in the pom.xml delivered by the server to have them available in your application.
Since you've used the "implementation" keyword, those dependencies are considered private to the .aar, and will not be listed in the pom.xml. So they will not be available in your aar, and not automatically imported into the project by gradle.
If you change to the api keyword to "api" instead of implementation, those dependencies become public, and should be listed in the generated pom.xml, and thus should be automatically imported into the project.
This is actually also true also with aar's inside modules, rather than referenced via external systems (e.g. implementation project(':mylibrary') ). If you need the dependencies of mylibrary to run the project, they need to be api.
For reference, you may want to take a look at the Android Studio Dependency Configurations Documentation.
If, however, you're manually including the arr via a files statement (e.g., implementation files('libs/my.aar')), then you don't get automatic dependency management, and you're going to have to add the libraries needed by your aar to the main project manually as well via copy and paste between the build.gradle files.
You can try using fat-aar to solve this https://github.com/kezong/fat-aar-android

In project 'app' a resolved Google Play services library dependency depends on another at an exact version

Trying to create a simple app with FireStore and Google Authentication. Having problem with the gradle:
In project 'app' a resolved Google Play services library dependency
depends on another at an exact version (e.g. "[15.0. 1]", but isn't
being resolved to that version. Behavior exhibited by the library will
be unknown.
Dependency failing: com.google.android.gms:play-services-flags:15.0.1
-> com.google.android.gms:play-services-basement#[
15.0.1], but play-services-basement version was 16.0.1.
The following dependencies are project dependencies that are direct or
have transitive dependencies that lead to the art ifact with the
issue.
-- Project 'app' depends onto com.google.firebase:firebase-firestore#17.1.5
-- Project 'app' depends onto com.firebaseui:firebase-ui-auth#4.2.0
For extended debugging info execute Gradle from the command line with
./gradlew --info :app:assembleDebug to see the dep endency paths to
the artifact. This error message came from the google-services Gradle
plugin, report issues at https://
github.com/google/play-services-plugins and disable by adding
"googleServices { disableVersionCheck = false }" to your b uild.gradle
file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "myapp.com"
minSdkVersion 19
targetSdkVersion 27
versionCode 11
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-firestore:17.1.5'
implementation 'com.firebaseui:firebase-ui-auth:4.2.0'
}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin
Project gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
}
}
Can somebody help me?
There are many answers here for individual solutions that do not really get down to the problem. Here is how to solve this in general:
As the original log output suggests, it is useful to run the build in the terminal with the following command:
./gradlew --info assembleDebug
This will give you a list of all dependencies that are involved in the conflict. It looks similar to this (I removed the package name stuff to make it a bit more readable):
Dependency Resolution Help: Displaying all currently known paths to any version of the dependency: Artifact(groupId=com.google.firebase, artifactId=firebase-iid)
-- task/module dep -> firebase-analytics#17.2.0
---- firebase-analytics:17.2.0 library depends -> play-services-measurement-api#17.2.0
------ play-services-measurement-api:17.2.0 library depends -> firebase-iid#19.0.0
-- task/module dep -> firebase-core#17.2.0
---- firebase-core:17.2.0 library depends -> firebase-analytics#17.2.0
------ firebase-analytics:17.2.0 library depends -> play-services-measurement-api#17.2.0
-------- play-services-measurement-api:17.2.0 library depends -> firebase-iid#19.0.0
-- task/module dep -> play-services-measurement-api#17.2.0
---- play-services-measurement-api:17.2.0 library depends -> firebase-iid#19.0.0
-- task/module dep -> firebase-iid#19.0.0
-- task/module dep -> firebase-messaging#17.1.0
---- firebase-messaging:17.1.0 library depends -> firebase-iid#[16.2.0]
-- task/module dep -> com.pressenger:sdk#4.8.0
---- com.pressenger:sdk:4.8.0 library depends -> firebase-messaging#17.1.0
------ firebase-messaging:17.1.0 library depends -> firebase-iid#[16.2.0]
From this list you get to know 2 things:
Where is the conflicting depedency found
What versions of the conflicting dependency are set up
In my case the conflicting dependency is firebase-iid: It's either #19.0.0 or #16.2.0
To fix this you must define the top-level dependency of the wrong firebase-iid explicitly in your build.gralde.
So in the upper log you can see that there are 2 examples of an out-dated version of firebase-iid#16.2.0. One comes from -- task/module dep -> firebase-messaging#17.1.0 the other one from a third-party library (pressenger). We don't have influence on the third-party library, so nothing to do here.
But for the other dependency, we have to declare it explicitly with the correct version:
implementation 'com.google.firebase:firebase-messaging:20.0.0'
Now the build works again. Happy ending :)
There's a known bug with Google Services 4.2.0 that may cause this. Downgrading your google-services version to 4.1.0 in your project's build.gradle may resolve the issue
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.1.0' //decreased from 4.2.0
}
}
The problem was it was missing a dependency.
Adding com.google.firebase:firebase-auth solved the issue.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-firestore:17.1.5'
// implementation'com.google.firebase:firebase-core:16.0.6'
// implementation'com.google.firebase:firebase-storage:16.0.5'
implementation'com.google.firebase:firebase-auth:16.1.0' => add this line
implementation 'com.firebaseui:firebase-ui-auth:4.2.0'
}
There was a bug related to google-services that was eventually fixed in version 4.3.3.
So you can either use 4.3.3 or the latest version (check here)
classpath 'com.google.gms:google-services:4.3.3' // or latest version
or downgrade to 4.1.0
classpath 'com.google.gms:google-services:4.1.0'
i added the latest version of firebase messaging to build.gradle (Module: app) in my project and problem solved
implementation 'com.google.firebase:firebase-messaging:20.0.0'
Your app/build.gradle might have these lemon color blocked on dependencies part in Android Studio like on the picture below,
These (lemon color blocks) mean it's not latest version of dependency. just put mouse on each block, then IDE (Android Studio) tells the numbers that have to be changed.
Updating all my Google Play Services libraries to the latest in ALL modules solved the issue for me. I don't see that you have any Google Play Services libraries, but I wanna leave this answer here to those that might find this useful.
My project was working fine (No build issues). All of a sudden, I got this error
"resolved Google Play services library dependency depends on another at an exact version.."
I figured out that it was because I was building offline.
If anyone gets the same error, check if you are building offline.
Thanks, but unfortunately, this didn't entirely work for me. I also had to add the following to my build.grade (Module:app)
implementation 'com.google.android.gms:play-services-flags:16.0.1'
implementation 'com.google.android.gms:play-services-basement:16.0.1'
The problem was fixed after upgrading this lib in my project's build.gradle:
classpath 'com.google.gms:google-services:4.3.3'
and these ones in the app module's build.gradle:
implementation 'com.google.firebase:firebase-core:17.3.0'
implementation 'com.google.firebase:firebase-messaging:20.1.5'
After this, use Android Studio's Clean menu
I am using One Signal and caught this error once a time.
The reason was:
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: 'com.android.application'
to put apply plugin for one signal before 'com.android.application'.
Maybe this will be useful for some other apply plugin too.
Add FCM to your App added Lower dependency Then I changed the dependency to the latest version this problem has solved.
compile 'com.google.firebase:firebase-messaging:17.3.4'
to
implementation 'com.google.firebase:firebase-messaging:20.0.0'
None of the other answers worked for me. My use-case is with React-Native 61+ trying to setup FCM and Analytics. What worked for me was using the latest google-services in android/build.gradle
dependencies {
classpath "com.android.tools.build:gradle:3.4.2"
classpath "com.google.gms:google-services:4.3.3" // Need the latest here
}
And then adding the gradle dependencies to android/app/build.gradle required for the products I'm using (in my case Analytics and Cloud Messaging) from here
dependencies {
...
// add the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-messaging:20.1.0'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
...
}
I just tried #live-love's accepted answer myself and agree with the approach.
It might be more precise, however, to correct your dependencies according to the latest Google Services library version.
For my case, it happened when I just added/activated a Firebase service to the app.
You need to follow the latest version in project and Gradle app.
My app/build.gradle
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//Android Support Design Library
implementation 'com.android.support:design:27.1.1'
//RecyclerView
implementation 'com.android.support:recyclerview-v7:27.1.1'
// Support multidex
implementation 'com.android.support:multidex:1.0.3'
// Firebase Core
// implementation 'com.google.firebase:firebase-core:16.0.1'
//Firebase Authentication
implementation 'com.google.firebase:firebase-auth:19.3.1'
// Firestore Firestore
implementation 'com.google.firebase:firebase-firestore:21.4.3'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
// glide
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
// Circle ImageView
implementation 'de.hdodenhof:circleimageview:2.2.0'
}
apply plugin: 'com.google.gms.google-services'
My project's build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Don't forget to sync the Gradle again.
The working solution for me was to remove "firebase-auth" and add "firebase-core" dependency. But after a couple of project rebuilds I started experiencing another compilation issue so I had to add the "firebase-auth" dependency in addition to the "firebase-core" in order to make it work:
implementation 'com.google.firebase:firebase-auth:19.0.0'
implementation 'com.google.firebase:firebase-core:17.0.1'
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
Add the line below in you Project's build.gradle (See image below)
classpath 'com.google.gms:google-services:4.3.3'
Then update your Firebase related packages by going to :
File > Project Structure > Dependencies > app
Update Firebase modules to latest version (See the image below)
In my case I am using :
implementation 'com.google.firebase:firebase-database:19.3.0'
implementation 'com.google.firebase:firebase-auth:19.3.1'
implementation 'com.google.firebase:firebase-messaging:20.1.7'
implementation 'com.google.firebase:firebase-core:17.4.0'
implementation 'com.google.firebase:firebase-storage:19.1.1'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
Don't forget to add :
apply plugin: 'com.google.gms.google-services'
See my Module's build.gradle file below.
The ML Kit library had versioning problems in the latest release.
Google Play services library dependency depends on another at an exact version error (thrown by the google-services plugin)
Here is the link to the solution.
https://firebase.google.com/support/release-notes/android#bom_v25-8-0
This is new thing happen to me that If your network is not secure and you are getting prompt of Untrusted Certificate.
If you will Accept or Reject, It will give this error until your network will not be secure.
You can work offline by checking Setting -> Gradle -> Offline Mode
If you used song haesuk answer, you need to do it for both build.gradle Project (classpath in dependencies), and in build.gradle app (implementations). Also do the same if you change builds for any libraries imported to the app.
I use suggestions provided by android studio and it changed implementations but did not change dependencies hence during build, there was a conflict between the two and it gave me same error.
I replicated the issue when I accidentally added com.google.firebase:firebase-ml-vision twice with different versions.
I resolved it by simply clearing the app-level dependencies block leaving just the default Android dependencies like so:
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'androidx.multidex:multidex:2.0.0'
}
This worked for me!
dependencies {
classpath "com.android.tools.build:gradle:3.4.2"
classpath "com.google.gms:google-services:4.3.3" // Need the latest here
}
dependencies {
...
// add the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-messaging:20.1.0'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
...
}
In my case updating the firebase-bom and play services library to their latest version solved the issue:
In app level gradle :
implementation platform('com.google.firebase:firebase-bom:30.3.2')
In project level gradle :
classpath 'com.google.gms:google-services:4.3.13'

Failed to resolve Firebase auth 15.0.0

I am new to android development environment and I need to connect my app to firebase but I am getting this error
Failed to resolve: firebase-auth-15.0.0
This error is shown in the statement:
implementation 'com.google.firebase:firebase-auth:16.0.1:15.0.0'
This statement contain details of two versions, I think the error is caused due to this, but this particular statement is provided by firebase itself. See the image:
I tried to change the above statement to
implementation 'com.google.firebase:firebase-auth:16.0.3'
But then firebase dependency is not setting up.
implementation 'com.google.firebase:firebase-auth:16.0.1:15.0.0'
Replace the above one with
implementation 'com.google.firebase:firebase-auth:16.0.1'
Instead of:
implementation 'com.google.firebase:firebase-auth:16.0.1:15.0.0'
Insert these two lines:
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.firebase:firebase-core:16.0.6'
Warnings should disappear
Try to use only implementation 'com.google.firebase:firebase-auth:16.0.1' in your code.
In your root build.gradle file add the repo:
allprojects {
repositories {
google()
jcenter()
// ...
}
}
Check if your firebase core is the same version than your firebase auth
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-auth:16.0.3'
and in your classpath an up version of 3.0.0
classpath 'com.android.tools.build:gradle:3.0.1' //up of this version
check this page to be up to date with firebase version:
https://firebase.google.com/support/release-notes/android#latest_sdk_versions
Try This add the dependency for Authentication to your app-level build.gradle file
implementation 'com.google.firebase:firebase-auth:16.0.3'
Worked with me, follow me.
I had this same problem. In the implementation of dependencies they are with the implementation 'com.google.firebase: firebase-auth: 16.0.2' ". The first is usually implemented manually and the second when we click the add button authentication with Firebase by the console in Android Studio and that is where the error begins. This button does not need to be triggered to authenticate the app. Just the first button to Connect with Firebase.
In the build.gradle file, keep only one Auth dependency.
Add firebase-core dependency and the latest versions of dependencies from this page:
fire base libraries
implementation 'com.google.firebase:firebase-auth:16.0.1:15.0.0'`
Replace the above with this -->
implementation 'com.google.firebase:firebase-auth:16.0.1'
I had the same problem. I updated the Android Studio and the Gradle ,it seems to work fine now

Crashlyitics not appearing in Firebase

My Crashlytics data is not appearing in the Firebase Crashlytics view. It does show "Crash-free statistics" as being 75%, so it appears to be recording some data. I also see the crashes appearing instantly both in Fabric and in the old Firebase Crash Reporting interface, as well as in the DebugView as general events but nothing in the Issues section of the Crashlytics page. I thought that perhaps my Fabric project had not been linked to my Firebase project, but when I tried doing it manually using this link https://www.fabric.io/firebase_migration/apps it tells me the projects are already linked, specifically it says Project already contains a linked app with that bundle ID and platform. Every time I open my app in Android studio I immediately run the command adb shell setprop debug.firebase.analytics.app ie.moses.keepitlocal so that my events will appear in the DebugView, perhaps this could be affecting it, but I doubt it.
Here is my project build.gradle file:
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.gms:google-services:3.3.0'
classpath 'io.fabric.tools:gradle:1.25.4'
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and this is the build.gradle for my specific app module
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
def supportLibraryVersion = '27.1.1'
android {
compileSdkVersion 27
defaultConfig {
applicationId "ie.moses.keepitlocal"
minSdkVersion 16
targetSdkVersion 27
versionCode 5
versionName "0.3.1-alpha"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
buildConfigField 'boolean', 'CRASHLYTICS', 'true'
}
release {
buildConfigField 'boolean', 'CRASHLYTICS', 'true'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.android.support') {
// Used to prevent conflicting versions of Android support library
// contained in other dependencies (e.g. all the firebase dependencies)
details.useVersion supportLibraryVersion
}
}
}
dependencies {
implementation files('libs/YouTubeAndroidPlayerApi.jar')
implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
implementation "com.android.support:recyclerview-v7:$supportLibraryVersion"
implementation "com.android.support:cardview-v7:$supportLibraryVersion"
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-crash:16.2.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
implementation 'com.google.guava:guava:26.0-android'
}
apply plugin: 'com.google.gms.google-services'
I am using a Button to force a crash with the following code (as I mentioned, these crashes appear almost immediately in Fabric and in the old Crash Reporting interface which has been deprecated and will be removed in 2 days!). Here is the code for the crash button:
Button crashButton = new Button(this);
crashButton.setText("Crash!");
crashButton.setOnClickListener(view -> {
throw new IllegalStateException("you hit the crash button!");
});
addContentView(crashButton, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
EDIT
I have just noticed that on the firebase transition status page it says "0/1 APP LINKED" and "NO PROJECTS YET".
I also need to reinstall the Crashlytics library from the Fabric plugin every time I open Android studio. The dependencies already exist in my gradle file but the plugin does not seem to recognise them.
EDIT
I am now trying to unlink fabric and firebase so I can try linking them again from fresh. I came across this question Unlink an existing firebase app?, but fabric is not even listed as an integration in my project.
Forget Fabric, it's not required. Just follow instructions in your Firebase console and Firebase documentation: https://firebase.google.com/docs/crashlytics/get-started#android
Don't mess with Fabric console, you should completly remove any calls to Fabric console and configure your project from scratch as Firebase doc says. As soon as you run app correctly configured, you will see Crashlytics panel in your Firebase console
The only solution I could find was as follows (I am including all steps exactly as I carried them out even if they may not be relevant):
I exported my realtime database to JSON and made a copy of my database rules.
I deleted my app from the Firebase project.
I deleted the Firebase project.
I deleted my project from Fabric.
I removed all references to Fabric, Crashlytics and the old Firebase Crash Reporting library from my project, this consisted of removing the dependencies from both my build.gradle files and deleting the fabric.properties file.
I ran gradlew.bat clean (I'm on Windows) on my project from the command line.
I did a Ctrl+Shift+F (search all project files) for the words fabric and crash just to make sure there was absolutely no remaining references to Fabric, Crashlytics or the deprecated Crash Reporting library (which was still a dependency in my build.gradle without me realising it because Firebase assistant tool added that as the crash reporting dependency when I first tried to get this working and then immediately told me it was deprecated :/ ).
I searched in File Explorer on windows for any files referencing "Fabric" or "Crash" (there weren't any).
I created a new project on Firebase.
I imported my realtime database from the previously exported JSON file and copy/pasted back in my rules.
I recreated my one test user account (thankfully the app is not yet in production :p).
I reenabled analytics (although this was simply a matter of going to the Analytics tab and seeing that it was already enabled as I still had the dependency in my build.gradle for my app module).
I went to the Crashlytics tab and saw the original screen explaining how to enable Crashlytics. This time however I did not create the project on Fabric or install the Fabric plugin, I only copied in the Fabric dependencies as I think #jake was suggesting, these can be found here https://firebase.google.com/docs/crashlytics/get-started?authuser=0.
I then tried to produce a crash using the method described here https://firebase.google.com/docs/crashlytics/force-a-crash?authuser=0.
And then voilĂ ! The crash appeared immediately in the Crashlytics tab of Firebase. No Fabric project, no Fabric plugin, just the dependencies.
This method had the added benefit of allowing me to be rid of extra databases and user properties I did not want (which Firebase does not currently allow you to remove once you create them >:( ), but this method obviously may not be feasible for anyone who already has a lot invested in their Firebase project and cannot simply start over. Luckily for me this was not too much of a pain.
add apply plugin: 'com.google.firebase.crashlytics' in app module
and dependencies {
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.1.1'
classpath 'com.google.gms:google-services:4.3.3'
} in project module
I had the same issue as you. I was able to link Fabric to Firebase after unlinking Crashlytics from Firebase following the instructions from this answer. Sadly this could only be done with building a custom url myself.

google-services.json No matching client found for package name with any module

I renamed my app module in application to presentation module.
I put google-services.json in my presentation/
Added classpath "com.google.gms:google-services:3.1.0"
Added plugin: apply plugin: 'com.google.gms.google-services'
And when i try Sync gradle, i get error:
Error:Execution failed for task ':presentation:processDebugGoogleServices'.
No matching client found for package name 'ru.company.acitive.activelife'
My build.gradle snippet:
dependencies {
classpath "com.android.tools.build:gradle:$android_plugin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.gms:google-services:3.1.0"
}
My presentation/build.gradle snippet:
dependencies {
...
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'
That means your app's application ID is "ru.company.acitive.activelife", but that same string wasn't found in your google-services.json file.
Looks like there's a typo in the part where it says "acitive". Should it be "active" instead?
In addition to ensuring that your gradle androidApplicationID matches your google-services.json (as discussed here), this message can also result from gradle not finding your keystore file.
Be sure to have these entries in your project level build.gradle file:
keystoreStoreFile = _________
keystoreStorePassword = ____________
keystoreKeyAlias = _______________
keystoreKeyPassword = ____________
And be sure to use the same four values when Android Studio prompts you for them during a "Generate Signed APK" opertation.
In my case, I was trying to build the example application ClassyTaxi that Google provides for illustrating subscription services. It has a project level build.gradle file that references a keystorePropertiesFile=keystore.properties. That properties file didn't exist, but there was an example-keystore.properties file that I renamed to keystore.properties and populated it with the four values I had selected. I then used those exact same four values when using Android Studio to generate my signed APK.
In my own case, the line below in my app-level build.gradle file was the culprit:
applicationIdSuffix ".debug"
I inherited the codebase from another developer, so I wasn't initially aware that this line existed.

Categories

Resources