47

We have followed the Add Firebase to your Android Project but we can't see the app receiving data in the Firebase Console.
And when we launch the app, the log says:

FirebaseInitProvider: FirebaseApp initialization unsuccessful

What does this mean? What are we doing wrong?
I can't find this error in the docs, nor here in StackOverflow.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
Salvatorelab
  • 11,614
  • 6
  • 53
  • 80
  • 2
    Same problem here. – tisch May 19 '16 at 17:55
  • Firebase shows an spinner all the time next to the app, and when you click on it, both the analytics and the crashes throw an error. It happens with an imported project from google console, new projects seem to work fine... – Salvatorelab May 19 '16 at 18:23
  • I tried creating a new project in firebase, but the problem still persists. – tisch May 19 '16 at 19:00

10 Answers10

40

What does this mean? What are we doing wrong?

Would assume, that the authentication did not succeed.

a) the buildscript repositories and dependencies for the project level build.gradle:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        
        // Android Gradle Plugin
        classpath "com.android.tools.build:gradle:3.3.2"

        // Google Services Plugin
        classpath "com.google.gms:google-services:4.2.0"
    }
}

b) the dependencies for the module level app/build.gradle (the Android Intel x86 images may still have a previous version of the Google Play Services installed, eg. 10.2.0 runs on the current x86 emulator, while eg. 11.8.0 runs on my physical ARM device). referencing play-services and firebase-core will include all of their modules, unless excluding some them. update: one has to reference all the libraries individually now. referencing com.google.android.gms:play‐services and com.google.firebase:firebase-core does not work anymore since 15.0.0.

android {
    ...
    buildTypes {
        debug {
            // suffixing the package name for debug builds,
            // in order to partially mute the crash-reporting
            // is an *optional* configuration (see below):
            applicationIdSuffix ".debug"
        }
    }
}

dependencies {

    // Google Play Services
    // https://developers.google.com/android/guides/releases
    implementation "com.google.android.gms:play-services-base:15.0.1"
    implementation "com.google.android.gms:play-services-auth:16.0.0"
    implementation "com.google.android.gms:play-services-identity:15.0.1"

    // Google Firebase
    // https://firebase.google.com/support/release-notes/android
    implementation "com.google.firebase:firebase-core:16.0.1"
    implementation "com.google.firebase:firebase-auth:16.0.3"
    implementation "com.google.firebase:firebase-config:16.0.0"
    implementation "com.google.firebase:firebase-storage:16.0.1"
    implementation "com.google.firebase:firebase-database:16.0.1"
    implementation "com.google.firebase:firebase-messaging:17.3.0"
    implementation "com.google.firebase:firebase-appindexing:16.0.1"
    implementation "com.google.firebase:firebase-functions:16.1.0"
    implementation "com.google.firebase:firebase-invites:16.0.1"
    // implementation "com.google.firebase:firebase-crash:16.0.1"
    implementation "com.google.firebase:firebase-ads:15.0.1"
    implementation "com.google.firebase:firebase-firestore:17.0.4"
    implementation "com.google.firebase:firebase-perf:16.0.0"

    // the inapp messaging may cause dependency conflicts: 
    // implementation "com.google.firebase:firebase-inappmessaging:17.0.0"
    // implementation "com.google.firebase:firebase-inappmessaging-display:17.0.0"
}

c) the bottom line of mobile/build.gradle should be:

// apply the Google Services Plugin
apply plugin: "com.google.gms.google-services"

d) make sure to have the (downloaded) credentials available at app/google-services.json; on the Firebase Console, one has to add both SHA1 (or SHA256) hashes, of the debug and the release keys, in order to have both builds authenticating properly; once it all matches, it should report:

I/FirebaseInitProvider: FirebaseApp initialization successful

It's all well documented, just see Setup Google Play Services, Firebase Quickstart or Crash Reporting; while I find this article on the Firebase Blog quite useful: Organizing your Firebase-enabled Android app builds, because it explains how to partially mute the crash-reporting. The release notes always announce the updates & changes.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • I wanna ask that why we need classpath 'com.google.gms:google-services:3.0.0' because latest version is : 9.4.0 ? – Dharvik shah Aug 06 '16 at 07:11
  • 1
    @Dharvikshah because there is only a `com.google.gms:google-services:3.0.0`. the one is packaged as Gradle plugin, the other one as library. `google-services` != `play-services`. also added some comments above. – Martin Zeitler Aug 09 '16 at 12:07
  • This causes an issue on my case: "Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536" . What is this, and how can I fix it? – android developer Oct 08 '16 at 23:46
  • @androiddeveloper you might exceed the 64K dex limit, `multiDexEnabled true` should help - while on Android > 5.0, this should be the default. see https://developer.android.com/studio/build/multidex.html (it's not exactly a problem with Firebase) – Martin Zeitler Oct 12 '16 at 11:16
  • @syslogic Can't be. It's a very small project. – android developer Oct 12 '16 at 21:00
  • @androiddeveloper the methods of the libraries also count towards that limit - and when building for API < 21, the package needs to be configured for multiDex, in order to have several 64K indexes available (that's at least how it was before multiDex became the default)... the `DexIndexOverflowException` is explicit. – Martin Zeitler Oct 15 '16 at 00:03
  • @androiddeveloper the referenced Firebase libraries might already exceed the 64K limit of a single index - configure `multiDexEnabled true` and add `compile 'com.android.support:multidex:1.0.1'` as dependency... when unzipping the apk, it also should get obvious. – Martin Zeitler Oct 15 '16 at 00:15
  • @syslogic Somehow I managed to make it work. And it wasn't because of what you wrote. Sorry and thank you – android developer Oct 15 '16 at 12:07
  • @syslogic In my case it was working perfectly fine for at least 30-40 times I have tests during development & then it started to give this error. In my case I'm using, targetSdkVersion 24, & com.google.gms:google-services:3.0.0. Any suggestion !! – CoDe Nov 19 '16 at 17:05
  • @Shubh not experiencing any sporadic errors here; just updated the answer yesterday, since it loads all the libraries at once (my actual `build.gradle` excludes half of the `play-services`, because it just bloats the resulting package). – Martin Zeitler Nov 20 '16 at 07:13
  • https://firebase.google.com/support/guides/firebase-android explains the changes. – Martin Zeitler Nov 20 '16 at 07:32
20

It happens when you dont have apply plugin: 'com.google.gms.google-services' in your app/build.gradle. Try adding it.

Also make sure you have Google Play services SDK installed in Android SDK Manager.

Sayyam
  • 959
  • 10
  • 22
3

The first thing I would advice you to check on is:

1) Have you included the <uses-permission android:name="android.permission.INTERNET" /> in your Manifest ?

Mayur Karmur
  • 2,119
  • 14
  • 35
Victor Mwenda
  • 1,677
  • 17
  • 16
3

Make sure you have added this line to App level build.gradle file

apply plugin: 'com.google.gms.google-services'
Mayur Karmur
  • 2,119
  • 14
  • 35
HemangNirmal
  • 621
  • 1
  • 8
  • 24
2

I too was facing a similar issue. I had imported my Google developer project to Firebase and had done all the steps as given in the instructions in the Android studio app and Firebase console i.e. adding the dependencies, google-services.json file and building again.

It still would not send data to the Firebase console. So, while going through the logcat, Firebase was unable to initialise as the google_app_id seemed to be missing.

After a lot of trial and error, I had to add a new string resource in my res/values/strings.xml file.

    <string name="google_app_id">YOUR_GOOGLE_APP_ID</string>

The Google App ID is available in the google_services.json file that you have downloaded from the Firebase console under the heading mobilesdk_app_id.

"client": [
    {
      "client_info": {
        "mobilesdk_app_id": "SOMETHING"
      }
    .
    .
    .

Copy the mobilesdk_app_id and paste it into your string resource inside res/values/strings.xml file with the name google_app_id.

Rebuild the code and it should work. :)

2

Whole problem occure because of two reason:

1. You have not taken permision in mainfest

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />

[enter image description here][1]

2. your gradle build version have bug- project level dependency

classpath 'com.google.gms:google-services:4.1.0'

replace with

classpath 'com.google.gms:google-services:4.0.1'

Alex Yu
  • 3,412
  • 1
  • 25
  • 38
Anuj Sachan
  • 40
  • 1
  • 6
1

In my case, I did all the things in Gradle properly. Even though it showed FirebaseApp initialization unsuccessful

I added com.google.android.c2dm.permission.RECEIVE permission in manifest which solved my problem.

 <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
 <uses-permission android:name="android.permission.INTERNET" />
piet.t
  • 11,718
  • 21
  • 43
  • 52
Jyoti JK
  • 2,141
  • 1
  • 17
  • 40
0

I got the same Logcat output.

Fixed it by updating my Google Play Services Dependency to 9.0.0 in my app/build.gradle

and updating

buildScript {
    //...
    dependencies {
        //...
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

in my project build.gradle to 3.0.0

Mayur Karmur
  • 2,119
  • 14
  • 35
RichardG
  • 41
  • 5
0

In my case I was trying to Selectively compile Google play Services. Instead of using

compile 'com.google.android.gms:play-services:9.4.0'

as described at: https://developers.google.com/android/guides/setup#ensure_devices_have_the_google_play_services_apk

I manually added maps and some other dependencies module from Google Play Services as

compile 'com.google.android.gms:play-services-maps:9.4.0'
compile 'com.google.android.gms:play-services-places:9.4.0'

Unfourtunately Firebase stoped working after this.

As a result I had to rollback and return to use

compile 'com.google.android.gms:play-services:9.4.0'

instead of selectively.

Juan Pablo
  • 1,213
  • 10
  • 15
0

In the build.gradle (project level)

change

    classpath 'com.google.gms:google-services:4.1.0'

to this

    classpath 'com.google.gms:google-services:4.0.1'