How to solve Firebase API initialization failure (Android + Firebase)

拜拜、爱过 提交于 2019-11-28 08:05:40

Well, after struggle a lot I found what was causing my problem. Basically I had two libraries modules - that happened to be of my own - each one of them importing different versions of com.android.support:appcompat-v7.* and google play services. Made all of them import the same version and problem is gone.

I met the same error, solved by upgrade firebase-core:

dependencies {    
    compile 'com.google.firebase:firebase-core:9.0.2'
}
Harpreet Singh

Care to see that all the dependencies should have same version

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
    {
      exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:25.2.0'
    implementation 'com.android.support:design:25.2.0'
    implementation 'com.android.support:support-v4:25.2.0'
    implementation 'com.google.firebase:firebase-auth:10.0.1'
    implementation 'com.android.support:cardview-v7:25.2.0'
    implementation 'com.google.firebase:firebase-database:10.0.1'
    testCompile 'junit:junit:4.12'
}
sunil KV

I faced the Same Issue, but after some r & d and I came to known the problem was in Gradle i.e, compile "com.android.support:support-v4:+" then I just removed the + and replaced actual version ie, compile "com.android.support:support-v4:23.1.0" then it started working

For me a completely unrelated import caused this error compile 'com.aurelhubert:ahbottomnavigation:1.3.3' When I removed it everything was fine

In my case, the problem occurs because i had put "apply plugin: 'com.google.gms.google-services'" inside the dependencies of the modules build.grandle insteand of putting it at the end of the file.

User9527

I had the same issue, fixed by upgrading to play-services-auth:10.0.1:

dependencies {
    ......
    //implementation 'com.google.android.gms:play-services-auth:9.0.0'
    implementation 'com.google.android.gms:play-services-auth:10.0.1'
    ....
}

You can check the dependencies with gradle command

./gradlew app:dependencies

As Edgar said ensure that all the dependency libraries has same version. If not then you can exclude that dependency using

compile('your dependency') {
    exclude group: 'lib to be removed'
}

And add that dependency yourself.

add compile 'com.google.android.gms:play-services:9.0.0' into your app level build.gradle file

Me, after struggle all night because my dependencies' version are the same. After adding Firebase Analytics, when I edited the code and run to my device my app crashed with Rejecting re-init on previously-failed class com.google.android.gms... I have to clean project and run again, then it worked fine but will be crashed again if I edit the code.

My problem was caused by "useProguard false" from following this guide https://developer.android.com/studio/build/shrink-code.html

    debug {
        minifyEnabled true
        useProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),
                'proguard-rules.pro'
    }

but I disabled Instant Run so remove "useProguard false" fixed my problem.

    debug {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'),
                'proguard-rules.pro'
    }
Dung

More complete answer for newbies. @Edgar is correct, Thanks!

Error: "Firebase API initialization failure" can be found in logcat of Android Monitor is due to incompatible library version. And it can be any libraries that you compile your app with in Project perspective: go to: Your-app-directory/app/build.gradle

In my case I have to match these 2 module version and that solved this error message:

implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-appindexing:16.0.1'

I attached here the screen shot so you can see all of it.

RAJESH KUMAR ARUMUGAM

In My case i forgot to add this with in App Level build

implementation 'com.google.firebase:firebase-messaging:9.6.0'

So i got the FireBase firebase-api-initialization-failure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!