Android Firebase API初始化在启动时失败
在应用程序启动时,将向控制台打印以下内容:Android Firebase API初始化在启动时失败,android,firebase,android-support-library,firebase-analytics,support-v4,Android,Firebase,Android Support Library,Firebase Analytics,Support V4,在应用程序启动时,将向控制台打印以下内容: Firebase API initialization failure. java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.google.firebase.FirebaseApp.
Firebase API initialization failure.
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.google.firebase.FirebaseApp.zza(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
//..
Caused by: java.lang.IllegalAccessError: Method 'void android.support.v4.content.ContextCompat.<init>()' is inaccessible to class 'com.google.firebase.iid.zzg'
也许这是问题的一部分,也许不是,但我觉得奇怪的是,最新版本的插件包含了较旧版本的Firebase(9.0.0
),而不是11.0.1
此外,如错误所述,问题是由以下原因引起的:
java.lang.IllegalAccessError: Method 'void android.support.v4.content.ContextCompat.<init>()'
java.lang.IllegalAccessError:Method'void android.support.v4.content.ContextCompat.()
这似乎表明v4支持库可能与该问题有关
造成这些问题的原因是什么?解决方案是什么?当我运行依赖项任务时,在app module
build.gradle
中没有将Google Play或Firebase库指定为依赖项,我在输出的顶部看到以下警告消息:
google-services plugin could not detect any version for com.google.android.gms or com.google.firebase, default version: 9.0.0 will be used.
please apply google-services plugin at the bottom of the build file.
向右滚动该消息以查看:将使用默认版本:9.0.0
在build.gradle
中的依赖项块之后必须应用插件的原因是它扫描库列表,以确定要用于处理的版本。您的模块依赖项必须至少包含一个Firebase或Google Play库,以便插件可以选择版本号
您在帖子的评论中指出,不需要明确依赖核心。文件里有吗?查看每个Firebase API(、实时数据库、存储、崩溃报告等)的安装指南,其中每个都包括将该API库添加到依赖项的步骤。您确定编译了Firebase 11.0.1吗?@cricket\u 007什么?
googleservices
插件包含库,如/gradlew app:dependencies
的输出所示,它添加了9.0.0
版本。该插件将分析添加到您的类路径中。它不会将Firebase的任何其他部分编译到您的实际应用程序中。请重新阅读本期。我确实阅读了本期。请重新阅读Firebase文档,注意编译'com.google.Firebase:Firebase core:11.0.1'
如果您单击将Android应用程序添加到Firebase项目中,它将启动一个模式,引导您完成这些步骤。最后一步指示开发人员将classpath'com.google.gms:google services:3.1.0'
包含在其顶级build.gradle
中,并在其应用程序级build.gradle
中应用插件。然后它提到默认情况下包含分析,并且显示不需要包含任何其他依赖项。注意,显式地将compile'com.google.firebase:firebase core:11.0.1'
添加到我的依赖项中确实会增加版本,如/gradlew app:dependencies
的输出所示。然而,虽然这确实减轻了最初的错误,但现在出现了一个奇怪的问题,即我的演示者对getView()
的调用(在本例中是活动)返回null。移除Firebase解决了这个问题,我觉得很奇怪。这个问题不一定与这个问题相关,所以我可能会提交另一个问题。
google-services plugin could not detect any version for com.google.android.gms or com.google.firebase, default version: 9.0.0 will be used.
please apply google-services plugin at the bottom of the build file.