将项目迁移到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'
}
我的项目成绩是:
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
}
}
我尝试过,但似乎无济于事,有人可以帮助我吗? 我将非常感谢
答案 0 :(得分:1)
您忘记在gradle(应用程序)中应用Google服务插件
dependencies {
....
}
apply plugin: 'com.google.gms.google-services'
还要确保您在项目级别的google-services
类路径是最新的