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

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

问题描述

昨天我用 17.1.1 更新了 Firestore 的依赖项,用 4.1.0 更新了 Google 服务的依赖项.现在在启动应用程序时它崩溃了.

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 服务更改为 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)

gradle 项目:

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

gradle 应用:

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 在启动时自动调用,该 ContentProvider 将在任何其他活动或服务之前初始化.您可以阅读 Doug 关于如何初始化的帖子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天全站免登陆