Android App + Firebase initializations fail - android

for my Android App, I need firebase integrated. So I followed the google tutorial.
now I am always getting after implementing firebase
E/FirebaseApp: Firebase API initialization failure.
when I run the App (on Real Device and Simulation)
Already saw that: Firebase database dependency crashes app
but he is working with old versions...
So my dependencies look like this:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
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.android.gms:play-services-location:16.0.0'
//implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.google.firebase:firebase-core:16.0.5'
}
apply plugin: 'com.google.gms.google-services'
here the projects gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
does anybody know what to do to get rid of this initalization problem?

I think, instead of adding "com.google.android.gms:play-services:", identify what is needed from playservices. Because play services is stuffed with 22 packages and you might not using all of it. This will bloat the apk size and you might cross 65K methods in your project.
I'd advice, you go through this link and pick necessary things you need from playservices.

Related

Android gradle libraries 'failure to resolve'

I'm trying to coax a number of android libraries to play nicely together but I'm becoming frustrated with the versioning system.
I've managed to get the firebase version of crashlytics working but I cannot currently get this to work well with admob:
in my app 'build.gradle' I have the following dependency section:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
implementation 'com.crashlytics.sdk.android:crashlytics-ndk:2.0.5'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.6'
implementation 'com.google.android.gms:play-services-ads:16.0.1'
}
Which produces this error:
Failed to resolve: com.google.android.gms:play-services-ads:16.0.1
'16.0.4' also fails whereas '17.1.1' produces this error:
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-core#16.0.1
-- Project 'app' depends onto com.google.android.gms:play-services-ads#17.1.1
thinking that maybe all of the dependencies need to be '17.1.1' results in gradle not finding 'com.google.firebase:firebase-core:17.1.1'
I doubt I'm alone in finding this version soup somewhat opaque. Is there an easier way to ensure a set of libraries that work well together?
Add:
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.android.gms:play-services-ads:17.1.1'
and in top level gradle file use the latest version of google play services:
classpath 'com.google.gms:google-services:4.0.2'
Note:
You need to add the google() repo in the top level gradle file, as specified in the firebase docs and also it should be before jcenter():
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.0.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
Please use the following version:
implementation 'com.google.android.gms:play-services-ads:17.1.1'
Also update the firebase-core library to version 16.0.4:
implementation 'com.google.firebase:firebase-core:16.0.4'

Failed to resolve: firebase-ads:15.0.1:15.0.0

I wanted to monetize my app using admob.
When i used the admob option available in firebase it asked me to add the following dependency 'com.google.firebase:firebase-ads:15.0.1:15.0.0'
but after the gradle build it gave me this error Failed to resolve: firebase-ads-15.0.0 so i used 'com.google.firebase:firebase-ads:12.0.1' which works great but with this one i can't see the ads. These are my dependencies :
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:26.1.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'
implementation 'com.daimajia.easing:library:2.0#aar'
implementation 'com.daimajia.androidanimations:library:2.3#aar'
implementation 'com.google.android.gms:play-services:12.0.1'
testImplementation 'junit:junit:4.12'
implementation 'com.google.firebase:firebase-core:12.0.1'
//implementation 'com.google.firebase:firebase-ads:12.0.1'
//implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.firebase:firebase-ads:15.0.1:15.0.0'
}
This is my project level gradle file
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
//classpath 'com.google.gms:google-services:4.0.1'
classpath 'com.google.android.gms:strict-version-matcher-plugin:1.0.0'
classpath 'com.google.gms:google-services:4.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Firebase core and ads compile version should same
Try this version 16.0.4
It looks like this :
implementation com.google.firebase:firebase-core:16.0.4
implementation 'com.google.firebase:firebase-ads:16.0.4'
change line :
implementation 'com.google.firebase:firebase-ads:15.0.1:15.0.0'
to
implementation 'com.google.firebase:firebase-ads:15.0.1'

Google Play Services - Could not find dependency

I'm building an app for the first time, it worked well with Google Map but a problem appeared when i added Firebase to my app.
I change some dependencies and this error occured after syncing with Gradle file :
Failed to resolve: com.google.android.gms:play-services:15.0.1
Install Repository and sync project
Show in File
Show in Project Structure dialog
Obviously i tried to click on Install Repository and sync project. During the installation, another error occured :
Could not find dependency "com.google.android.gms:play-services:15.0.1"
Here is my dependencies in build.gradle file. As you can see, i didn't forget to use implementation 'com.google.android.gms:play-services:15.0.1'.
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-annotations:28.0.0-alpha3'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.android.gms:play-services:15.0.1'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.google.android.gms:play-services-identity:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
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'
}
I found people with the same problem and i tried lots of proposed solutions, but the problem isn't solved.
You can see below my build.gradle project file.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.google.gms:google-services:4.0.1'
classpath 'com.android.tools.build:gradle:3.3.0-alpha03'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Still getting warning : Configuration 'compile' is obsolete and has been replaced with 'implementation'

I have replaced every occurrence of compile by implementation in my project's build.gradle, but I'm still getting this warning :
I tried to look for "compile " in the whole project but no match was found. So what could be the cause?
I've updated com.google.gms:google-services from 3.1.1 to 3.2.0 and the warning stopped appearing.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.1.0")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath("com.google.gms:google-services:3.2.0")
}
}
I have one same Warning caused to com.google.gms:google-services.
The solution is to upgrade classpath com.google.gms:google-services to classpath 'com.google.gms:google-services:3.2.0' in file in build.gradle Project:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.2.0'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
In Android Studio verion 3.1 dependencies complie word is replaced to
implementation
dependencies with Warning in android studio 3.1
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
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'
}
dependencies OK in android studio 3.1
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
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'
}
Gradel generate by Android Studio 3.1 for new project.
Visit https://docs.gradle.org/current/userguide/dependency_management_for_java_projects.html
For details https://docs.gradle.org/current/userguide/declaring_dependencies.html
I've updated com.google.gms:google-services from 3.2.0 to 3.2.1 and the warning stopped appearing.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.google.gms:google-services:3.2.1'
}
}
Using the currently latest version of the google gms services resolved it for me.
In the project level build.gradle:
buildscript {
...
dependencies {
classpath 'com.google.gms:google-services:3.2.1'
...
}
}
Open up your build.gradle file located here:
This is the old way of writing the dependency libraries (for gradle version 2 and below):
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile files('libs/volley.jar')
compile 'com.android.support:support-v4:21.+'
}
This is the new (right) way of importing the dependencies for gradle version 3:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation files('libs/volley.jar')
implementation 'com.android.support:support-v4:21.+'
}
Reply by google : https://issuetracker.google.com/issues/74048134
There would be some dependency still using compile, check your application dependencies and transitive dependencies carefully.
https://issuetracker.google.com/issues/72479188 indicates that plugins sometimes can introduce "compile" dependencies and that's what triggers the warning. Probably just easiest to star that issue and wait until they fix it to point out which plugins are causing the issue.
No need to remove the line. As Jkrevis wrote, update the com.google.gms:google-services to 3.2.0 and it stops the warnings.
In my case,it is cause by Realm library,after I update it to latest version(5.1.0 so far) of Realm,the problem solved!
Here is the working gradle script:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "io.realm:realm-gradle-plugin:5.1.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.2.1'
}
}
I encounter this problem without using com.google.gms:google-services.
The solution solving this kind problem as below:
check build.gradle files of all projects and modules. Or just global search key word 'compile' to find where cause this warning.
if above method cannot solve this warning, then use CLI Command,
./gradlew assembleDebug -d > gradle.log
print detail debug information to a file named gradle.log or any else, as the information is too much. Then search word "WARNING" to find the position in gradle.log, usually you can find what dependence or plugin cause the warning.
Just updating google-service version did not work for me.
First make sure all your dependencies compile are replaced with implementation.
Update all dependencies in your project. Because if one of your dependency is having compile then your project will show this error. So update all dependencies version.
I have tried changing the google gms services to the latest com.google.gms:google-services:3.2.1 in Android Studio 3.0.1 but the warning still persists.
As recommended by the compiler,I changed all compile dependencies to implementation and testCompile to testImplementation like this..
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:mediarouter-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.google.firebase:firebase-ads:12.0.1'
implementation 'com.google.firebase:firebase-crash:12.0.1'
implementation 'com.google.firebase:firebase-core:12.0.1'
implementation 'com.google.firebase:firebase-messaging:12.0.1'
implementation 'com.google.firebase:firebase-perf:12.0.1'
implementation 'com.google.firebase:firebase-appindexing:12.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
And finally the warning is removed!
go to your build.gradle file in project level you will find the following lines highlighted
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4' //place your cursor over here
//and hit alt+enter and it will show you the appropriate version to select
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.0.2' //the same as previously
}
In my case it was an old dependency that was using compile for the transitive dependencies : com.jakewharton.hugo
After removing it from my gradle it compiled.
The workaround to solve this problem was for me that I used an older version of Gradle, which can be found here:
I used the gradle-3.0-rc-1-src version, but others may work too, although probably it should not be newer than the 3.0-version.
First extract the zip file to anywhere you like.
Then go to File -> Settings -> Build, Execution, Deployment -> Gradle and change the setting to Use local gradle distribution. After that make sure that the Gradle Home-field is pointing to the .gradle directory in the directory you just unzipped to.
Rebuild the project and everything should be ok.
The current version is 4.2.0:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.2.0'
}
}
Google updated it's services recently in September 2021. Gave update and I faced same issue then I update the build.gradle file in android studio
Old version with issue
classpath 'com.google.gms:google-services:4.3.3'
Updated code in build.gradle
classpath 'com.google.gms:google-services:4.3.10'
You can do this two options:
Add classpath 'com.google.gms:google-services:3.2.0' in ur project: build.gradle dependencies
and
Replace your module: build.gradle in dependency from complile with implementation
and you wont get any warning messages.
Just add from build.gradle from build script
classpath 'com.google.gms:google-services:3.2.0'
and all of the dependencies "compile" replace to "implementation".
that worked from me.
For me changing compile to implementation fixed it
Before
compile 'androidx.recyclerview:recyclerview:1.0.0'
compile 'androidx.cardview:cardview:1.0.0'
//Retrofit Dependencies
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
After
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
//Retrofit Dependencies
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
I treid all the solutions mentioned here, but no luck.
I found in my build.gradle file as below:
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
I just changed it as below and saved and tried build success.
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
Hope that you're affected with build.gradle(app)
If do so , follow this step
Replace compile with androidTestImplementation in build.gradle
androidTestImplementation 'com.android.support:appcompat-v7:27.1.1'
androidTestImplementation 'com.android.support:design:27.1.1'
so simple ! hope this will solve
In my case the issue was the Google services gradle plugin with the following line in the gradle file:
apply plugin: 'com.google.gms.google-services'
Removing this resolved the issue
go to you build.gradle (app level)
build.gradle module app
and replace the word "compile" by "implementation"
it will work 100%

Cannot resolve GoogleSignIn and GoogleSignInClient

I am not able to use GoogleSignIn(com.google.android.gms.auth.api.signin.GoogleSignIn
) and GoogleSignInClient(com.google.android.gms.auth.api.signin.GoogleSignInClient
) while implementing Google Sign In in Android Studio while I can access other classes in App like
com.google.android.gms.auth.api.signin.GoogleSignInAccount;
com.google.android.gms.auth.api.signin.GoogleSignInOptions;
com.google.android.gms.common.SignInButton;
A strip down version of my build.gradle(app) file is as follow
android {
}
dependencies {
compile 'com.google.android.gms:play-services-auth:11.4.2'
compile('com.google.api-client:google-api-client-android:1.23.0') {
exclude group: 'org.apache.httpcomponents'
}
compile('com.google.apis:google-api-services-gmail:v1-rev72-1.23.0') {
exclude group: 'org.apache.httpcomponents'
}
implementation 'com.google.gms:google-services:3.1.2'
}
apply plugin: 'com.google.gms.google-services'
and my build.gradle(package) is
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.gms:google-services:3.1.2'
}
}
Any help would be appreciated
add this to your app-level dependency
compile 'com.google.android.gms:play-services-auth:12.0.1'
I was having the same issue
GoogleSignIn and GoogleSignInClient were introduced in version Google Play services SDK version 11.6. In older versions GoogleApiClient was used.
So try changing the compile 'com.google.android.gms:play-services-auth:11.4.2' to 'com.google.android.gms:play-services-auth:12.0.1' in dependencies
dependencies
{
compile 'com.google.android.gms:play-services-auth:12.0.1'
}
For me I was applying a plugin for the google play services in my app's build.gradle:
apply plugin: 'com.google.gms.google-services'
along with that in my Project's Build.gradle I had google services.
buildscript {
ext.kotlin_version = '1.1.60'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.google.gms:google-services:3.1.2' // <== this guy
classpath 'com.android.tools.build:gradle:3.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
I remember I added them with some compiling issues. But apparently I didn't need them.
By removing them I found there were no more issues with the gms versions.
EDIT
So removing solved my issue initially, but gave me issues later with google sign in. adding the apply plugin: 'com.google.gms.google-services' to the bottom of my projects gradle instead of at the top did actually solve it.
In the build.gradle Module script, I had to add these two dependencies, then "Sync Now" and issue resolved for me.
dependencies {
// Your own command lines
//...
compile 'com.google.android.gms:play-services-drive:11.8.0'
compile 'com.google.android.gms:play-services-auth:11.8.0'
}
Can't you use any newer version? e.g. 11.6.0.
Try to update your Google Repository as well.
(Tools->Android->SDK Manager->SDK Tools under Support Repository)
Add this line in build.gradle module file under dependencies.
implementation 'com.google.firebase:firebase-auth:21.0.1'
For example:
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.firebase:firebase-database:20.0.2'
implementation 'com.google.android.gms:play-services-auth:20.2.0'
implementation 'com.google.firebase:firebase-firestore:24.0.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
implementation 'de.hdodenhof:circleimageview:3.1.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

Categories

Resources