默认FirebaseApp在此过程中未初始化。 -Android Studio错误

时间:2018-08-31 20:42:22

标签: android firebase authentication

我无法将 Firebase身份验证 n与 FirebaseUI 结合使用。当我运行我的应用程序时,出现以下问题:“默认FirebaseApp在此过程中未初始化。请确保先调用FirebaseApp.initializeApp(上下文)。”

在我的应用程序/ build.gradle中,我具有依赖项:

     implementation 'com.google.firebase: firebase-core: 16.0.1'
     implementation 'com.google.firebase: firebase-auth: 16.0.1'
     implementation 'com.google.firebase: firebase-database: 16.0.1'
     implementation 'com.firebaseui: firebase-ui-auth: 4.1.0'

和末尾的"apply plugin: 'com.google.gms.google-services"

在我的模块/ build.gradle中,我具有依赖项:

classpath 'com.google.gms: google-services: 4.1.0'
classpath 'com.android.tools.build:gradle:3.3.0-alpha07'

我已经将googleservices.json导出到“ app”文件夹。我没有选择,问题继续。有什么建议吗?

Logcat:

---------崩溃开始

08-31 19:40:12.718 2865-2865/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: br.com.luccas.buscaperto, PID: 2865
    java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.luccas.buscaperto/br.com.luccas.buscaperto.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process br.com.luccas.buscaperto. Make sure to call FirebaseApp.initializeApp(Context) first.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process br.com.luccas.buscaperto. Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(SourceFile:218)
        at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
        at br.com.luccas.buscaperto.MainActivity.instantiateUser(MainActivity.java:89)
        at br.com.luccas.buscaperto.MainActivity.onCreate(MainActivity.java:64)
        at android.app.Activity.performCreate(Activity.java:6237)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5417) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

我的最高级别:

buildscript {
    ext {
        release = [
                versionName: "6.1.0-rc01",
                versionCode: 6100
        ]

        setup = [
                compileSdk: 28,
                buildTools: "28.0.2",
                minSdk    : 14,
                targetSdk : 28
        ]

        versions = [
                androidX: '1.0.0-rc01'
        ]
    }

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

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

我的应用级别优惠券:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "br.com.luccas.buscaperto"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '28.0.2'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "androidx.legacy:legacy-support-v4:${versions.androidX}"
    implementation "androidx.appcompat:appcompat:${versions.androidX}"
    implementation "androidx.constraintlayout:constraintlayout:${versions.androidX}"
    implementation "androidx.recyclerview:recyclerview:${versions.androidX}"
    implementation "androidx.annotation:annotation:${versions.androidX}"

    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.mikepenz:materialdrawer:6.1.0-rc01'
    implementation "com.google.android.material:material:${versions.androidX}"

    implementation 'com.google.firebase:firebase-core:16.0.3'
    implementation 'com.google.firebase:firebase-auth:16.0.3'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.firebaseui:firebase-ui-auth:4.1.0'

    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
apply plugin: 'com.google.gms.google-services'

7 个答案:

答案 0 :(得分:3)

请升级您的项目级别的gms依赖项,我已升级到 4.2.0 ,并且有效

classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'

答案 1 :(得分:2)

尝试这样做:

implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.firebaseui:firebase-ui-auth:4.1.0

并更改此内容:

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

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

答案 2 :(得分:0)

您需要更新google_services.json文件。从firebase下载它并替换为现有的。在json文件中,有一个配置会自动合并内容提供程序,默认情况下,在使用gradle构建时,该内容提供程序会将您的Firebase应用程序与清单合并。但是您当前的json文件缺少该配置。因此,您需要替换或需要调用static FirebaseApp(Context)方法来解决此问题。Read Here

在应用启动器的onCreate方法中将其添加为

...... onCreate(.....)
       {
          FirebaseApp.initializeApp(this);
          ..........   

       }

答案 3 :(得分:0)

它通过降级工作到: classpath 'com.android.tools.build:gradle:3.2.0-alpha14'

答案 4 :(得分:0)

我的应用中存在相同的问题, 但根据https://issuetracker.google.com/issues/112716914,此问题跟踪器 我已更新为版本类路径'com.google.gms:google-services:4.2.0',问题已解决。

答案 5 :(得分:0)

我遇到了同样的问题,问题出在google-services.json格式不正确,以及google-services.json在文件中的跟随方式

  

评论开始   克隆项目,并在firefox中创建数据库,并将程序包名称命名为.....

答案 6 :(得分:-1)

在build.gradle项目级别中编辑您的依赖项:

     classpath 'com.android.tools.build:gradle:3.3.2'
     classpath 'com.google.gms:google-services:4.2.0' 

Oncreate方法添加以下内容:

     FirebaseApp.initializeApp(this);