具有新依赖项的Firestore崩溃应用 [英] Firestore crashing app with new dependencies

查看:56
本文介绍了具有新依赖项的Firestore崩溃应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天,我用 17.1.1 更新了Firestore的依赖关系,并用 4.1.0 更新了Google Services的依赖关系.现在,在启动应用程序时,它会崩溃.

Yesterday I updated the dependencies of Firestore with 17.1.1 and Google Services with 4.1.0. Now while launching the app it crashes.

注意:

如果我将Google Services更改为 4.0.2 ,则Firestore会正确初始化,并且该应用程序将按预期运行.

If I change Google Services to 4.0.2, the Firestore initializes properly and the app works as expected.

classpath 'com.google.gms:google-services:4.0.2'


更新:

更改为 4.2.0 可行.

日志:

Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.
... I/FirebaseInitProvider: FirebaseApp initialization unsuccessful

错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{\...\/\...\.ui.MessageActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process \...\. Make sure to call FirebaseApp.initializeApp(Context) first.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process \...\. Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.2:240)
        at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@17.1.1:68)
        at \...\.ServiceLocator.provideFirestore(ServiceLocator.java:18)
        at \...\.ServiceLocator.provideMessageRepository(ServiceLocator.java:28)
        at \...\.ServiceLocator.provideMessageViewModelFactory(ServiceLocator.java:33)
        at \...\.ui.MessageActivity.onCreate(MessageActivity.java:112)
        at android.app.Activity.performCreate(Activity.java:7009)
        at android.app.Activity.performCreate(Activity.java:7000)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

分级项目:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0-alpha13'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.1.0'
    }
}

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

分级应用:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "..."
        minSdkVersion 22
        targetSdkVersion 28
        versionCode 8
        versionName "1.0.8"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    // ...
    buildToolsVersion '28.0.3'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    // ...
    // Firestore
    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation 'com.google.firebase:firebase-firestore:17.1.1'
    implementation 'com.google.firebase:firebase-auth:16.0.4'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'com.google.firebase:firebase-ads:16.0.1'
    implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
    // Crash Reports
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
}

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

推荐答案

无需使用 FirebaseApp.initializeApp(context).仅使用依赖项就足够了.因此,如果您执行标准集成,则无需手动调用它,因为它将通过 ContentProvider 自动启动,该启动将在任何其他Activity或Service之前初始化.您可以在如何初始化中阅读道格的帖子Android上的Firebase .

There is no need to use FirebaseApp.initializeApp(context). Using only the dependencies is enough. So you shouldn't ever have to call it manually if you performed the standard integration, as it will be invoked automatically a startup via a ContentProvider that will initialize before any other Activity or Service. You can read Doug's post regarding on how to initialize Firebase on Android.

您的代码中的问题是您的项目正在使用gradle的 alpha13 版本.要解决此问题,请更改以下代码行:

The problem in your code is that your are using for your project the alpha13 version for your gradle. To solve this, please change the following line of code:

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

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

将解决此问题.

这篇关于具有新依赖项的Firestore崩溃应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆