android - 迁移到 Androidx 后 Firebase 18.X.X 出现问题

标签 android firebase firebase-realtime-database firebase-authentication

我在将我的项目迁移到 Androidx 后遇到了很多问题,其中之一是当我尝试获取数据库实例时:

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

这是错误:

 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:firebase-common@@17.1.0:186)
    at com.google.firebase.database.FirebaseDatabase.getInstance(com.google.firebase:firebase-database@@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)

我的 Gradle 是下一个:

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'

}

我的项目 gradle 是:

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
    }
}

我尝试了,但似乎没有任何效果,有人可以帮助我吗? 我将不胜感激

最佳答案

您忘记在您的 gradle (app) 中应用 google services 插件

dependencies {
    ....
}

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

还要确保项目级别的 google-services 类路径是最新的

关于android - 迁移到 Androidx 后 Firebase 18.X.X 出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56940759/

相关文章:

android - 当我尝试在选项卡之间切换时应用程序崩溃

android - 通过 Intent 将资源传递给 Activity

firebase - 允许基于映射键的访问

swift - 事件指示器不会完成操作

java - 我得到我的 Firebase 用户 Uid 但它的 dataSnapshot 键值返回 null

html - Angular 4 firebase下拉选择标签选项

ios - Firebase SWIFT 中的多个查询和子查询

java - 解析使用对象: Doesn't display even though record exists创建表

android - 来自 HttpClient 的重复请求

java - 如何比较 Firebase 中的时间戳数组?