Rajarshi
Rajarshi

Reputation: 2509

Firestore crashing app with new dependencies

Yesterday I updated the dependencies of Firestore with 17.1.1 and Google Services with 4.1.0. Now while launching the app it crashes.

Note:

If I change Google Services to 4.0.2, the Firestore initializes properly and the app works as expected.

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

Update:

Changing to 4.2.0 works.


Logs:

Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.
... I/FirebaseInitProvider: FirebaseApp initialization unsuccessful

Error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{\...\/\...\.ui.MessageActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process \...\. Make sure to call FirebaseApp.initializeApp(Context) first.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process \...\. Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.2:240)
        at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@17.1.1:68)
        at \...\.ServiceLocator.provideFirestore(ServiceLocator.java:18)
        at \...\.ServiceLocator.provideMessageRepository(ServiceLocator.java:28)
        at \...\.ServiceLocator.provideMessageViewModelFactory(ServiceLocator.java:33)
        at \...\.ui.MessageActivity.onCreate(MessageActivity.java:112)
        at android.app.Activity.performCreate(Activity.java:7009)
        at android.app.Activity.performCreate(Activity.java:7000)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

gradle Project:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0-alpha13'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.1.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

gradle app:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "..."
        minSdkVersion 22
        targetSdkVersion 28
        versionCode 8
        versionName "1.0.8"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    // ...
    buildToolsVersion '28.0.3'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    // ...
    // Firestore
    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation 'com.google.firebase:firebase-firestore:17.1.1'
    implementation 'com.google.firebase:firebase-auth:16.0.4'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'com.google.firebase:firebase-ads:16.0.1'
    implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
    // Crash Reports
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
}

apply plugin: 'com.google.gms.google-services'

Upvotes: 1

Views: 2005

Answers (3)

Farry
Farry

Reputation: 21

Switching to 4.2.0 Solves the issue.

Upvotes: 0

Alex Mamo
Alex Mamo

Reputation: 138834

There is no need to use FirebaseApp.initializeApp(context). Using only the dependencies is enough. So you shouldn't ever have to call it manually if you performed the standard integration, as it will be invoked automatically a startup via a ContentProvider that will initialize before any other Activity or Service. You can read Doug's post regarding on how to initialize Firebase on Android.

The problem in your code is that your are using for your project the alpha13 version for your gradle. To solve this, please change the following line of code:

classpath 'com.android.tools.build:gradle:3.3.0-alpha13'

to

classpath 'com.android.tools.build:gradle:3.2.0'

Will solve this issue.

Upvotes: 5

Kirill Rakhman
Kirill Rakhman

Reputation: 43831

This is a confirmed bug in the play-services plugin 4.1.0 according to https://issuetracker.google.com/issues/112716914. The answer is to use an earlier version, e.g. 4.0.2.

Edit: Version 4.2.0 is released where the bug is fixed.

Upvotes: 4

Related Questions