Ad

Problem With Firebase 18.X.X After Migrate To Androidx

I have a lot of problems after I migrate my project to Androidx, one of them is when I try to get the instance for database:

databaseReference = FirebaseDatabase.getInstance().getReference();

this is the error:

 Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process corp.brigadas.com.mexis. Make sure to call FirebaseApp.initializeApp(Context) first.
    at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:[email protected]@17.1.0:186)
    at com.google.firebase.database.FirebaseDatabase.getInstance(com.google.firebase:[email protected]@17.0.0:56)
    at corp.brigadas.com.mexis.presenters.Implements.LoginPresenterImp.onCreate(LoginPresenterImp.java:28)
    at corp.brigadas.com.mexis.views.activities.LoginActivity.preparativos(LoginActivity.java:70)
    at corp.brigadas.com.mexis.views.activities.LoginActivity.onCreate(LoginActivity.java:62)
    at android.app.Activity.performCreate(Activity.java:7224)
    at android.app.Activity.performCreate(Activity.java:7213)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)

and my Gradle is the next:

repositories {
    mavenCentral()
    maven { url 'https://maven.google.com' }
    jcenter()
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout: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.firebase:firebase-auth:18.0.0'
    implementation 'com.google.firebase:firebase-storage:18.0.0'
    implementation 'com.google.firebase:firebase-firestore:20.1.0'
    implementation 'com.google.firebase:firebase-database:18.0.0'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    implementation 'com.google.firebase:firebase-core:17.0.0'
    implementation 'com.android.support:customtabs:28.0.0'
    implementation 'com.firebase:geofire-android:2.3.1'
    implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta2'
    implementation 'com.google.android.libraries.places:places-compat:1.1.0'
    implementation 'jp.wasabeef:glide-transformations:4.0.0'
    implementation 'jp.co.cyberagent.android:gpuimage:2.0.0'

}

my project-gradle is:

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath 'com.google.gms:google-services:4.3.0'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

I try but nothing seems to work, can someone help me? I would be very grateful

Ad

Answer

You forgot to apply the google services plugin at your gradle (app)

dependencies {
    ....
}

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

Also make sure that your google-services classpath at your project level is up to date

Ad
source: stackoverflow.com
Ad