FirebaseAuth.getInstance()崩溃

时间:2019-12-19 21:58:29

标签: java android

im创建一个包含登录系统的帐户,登录后我们进入主活动,您将看到一个导航抽屉活动。 在我启动登录系统之前,我的登录系统运行良好,但是只有退出按钮,我的主活动却空着。但是现在我将主要活动更改为导航抽屉活动。 在这里我遇到了崩溃,当我调试时发现崩溃发生在FirebaseAuth.getInstance()上,当我进入代码内部时,我发现ActivityThread.java类充满了错误,就像您在照片中看到的那样,已经尝试过FirebaseApp.initializeApp(Context),但是它不起作用,所以任何人都可以告诉我为什么它不断崩溃。

下面您可以看到我的build.gradle和错误消息

image

apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
    applicationId "com.example.greenway"
    minSdkVersion 16
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.firebase:firebase-core:17.2.1'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-database:19.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'

}

E / Android运行时:致命异常:主要     流程:com.example.greenway,PID:7810     java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.greenway / com.example.greenway.Login}:java.lang.IllegalStateException:默认FirebaseApp在此过程com.example.greenway中未初始化。确保首先调用FirebaseApp.initializeApp(Context)。         在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)         在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)         在android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)         在android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)         在android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)         在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2016)         在android.os.Handler.dispatchMessage(Handler.java:107)         在android.os.Looper.loop(Looper.java:214)         在android.app.ActivityThread.main(ActivityThread.java:7356)         在java.lang.reflect.Method.invoke(本机方法)         在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:492)         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)      由以下原因引起:java.lang.IllegalStateException:在此过程com.example.greenway中未初始化默认的FirebaseApp。确保首先调用FirebaseApp.initializeApp(Context)。         com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common @@ 19.3.0:184)         com.google.firebase.auth.FirebaseAuth.getInstance(com.google.firebase:firebase-auth @@ 19.2.0:1)         在com.example.greenway.Login.onCreate(Login.java:41)         在android.app.Activity.performCreate(Activity.java:7802)         在android.app.Activity.performCreate(Activity.java:7791)         在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)         在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)         在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)         在android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)         在android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)         在android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)         在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2016)         在android.os.Handler.dispatchMessage(Handler.java:107)         在android.os.Looper.loop(Looper.java:214)         在android.app.ActivityThread.main(ActivityThread.java:7356)         在java.lang.reflect.Method.invoke(本机方法)         在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:492)         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

1 个答案:

答案 0 :(得分:0)

您似乎没有应用Google插件

应用插件:“ com.google.gms.google-services”