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

前端 未结 12 1297
渐次进展
渐次进展 2020-12-29 20:02

I recently needed to use Google GCM in my project. From its website it is said:

Firebase Cloud Messaging (FCM) is the new version of GCM. It inherits

相关标签:
12条回答
  • 2020-12-29 20:35

    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'
    }
    
    0 讨论(0)
  • 2020-12-29 20:36

    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'
        ....
    }
    
    0 讨论(0)
  • 2020-12-29 20:43

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

    0 讨论(0)
  • 2020-12-29 20:46

    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'
        }
    
    0 讨论(0)
  • 2020-12-29 20:49

    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.

    0 讨论(0)
  • 2020-12-29 20:53

    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.

    0 讨论(0)
提交回复
热议问题