Android库中的Firebase依赖项:无法在空对象上调用方法get() [英] Firebase dependency in Android Library: Cannot invoke method get() on null object
问题描述
在将firebase依赖项添加到android库时,我遇到了构建问题.
I'm experiencing a build issue when adding a firebase dependency to a android library.
我的设置如下
/settings.gradle
include ':module-lib'
include ':module-app'
/build.gradle
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:4.0.0'
}
}
/module-lib/build.gradle
apply plugin: 'com.android.library'
android {
...
}
dependencies{
api "com.google.firebase:firebase-config:16.0.0"
}
/module-app/build.gradle
apply plugin: 'com.android.application'
android {
...
}
dependencies {
implementation project(':module-lib')
}
apply plugin: 'com.google.gms.google-services'
短日志:
$ ./gradlew clean build
Starting a Gradle Daemon, 1 busy and 2 stopped Daemons could not be reused, use --status for details
Parallel execution is an incubating feature.
> Configure project :module-app
Detected alwaysUpdateBuildId set to false while obfuscation is enabled. This may result in obfuscated stack traces in Crashlytics.
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
> Task :module-lib:compileDebugAidl FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Failed to notify dependency resolution listener.
> Cannot invoke method get() on null object
> Cannot invoke method get() on null object
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 18s
13 actionable tasks: 8 executed, 5 from cache
您可以在此粘贴框中找到原始错误的完整堆栈跟踪记录
You can find the full stacktrace of the original error in this pastebin
有趣的事情是,module-lib
仅包含一个占位符,为空且无用的类.如果我从module-lib
中删除了Firebase依赖项并将其移至module-app
,则构建工作正常.
The funny thing is that module-lib
only contains a placeholder, empty and useless class. If I removed the firebase dependency from module-lib
and move it to module-app
, the build works fine.
我没有使用Android Studio,所以这纯粹是Gradle和/或插件 和/或依赖项问题.
I'm not using Android Studio, so this is a purely Gradle and/or plugin and/or dependencies issue.
还请注意
./gradlew clean // Always succeds
./gradlew build // Sometimes works with above error
./gradlew clean build // Always fails with above error
应用库插件com.android.library
的模块中包含的任何firebase-*
依赖项也会发生这种情况.
This also happens with any firebase-*
dependency included in a module that applies the library plugin com.android.library
.
更多环境信息
$ ./gradlew -version
------------------------------------------------------------
Gradle 4.7
------------------------------------------------------------
Build time: 2018-04-18 09:09:12 UTC
Revision: b9a962bf70638332300e7f810689cb2febbd4a6c
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 1.8.0_162 (Oracle Corporation 25.162-b12)
OS: Mac OS X 10.13.4 x86_64
任何提示或技巧都非常受欢迎:)
Any clues or tips are more than welcome :)
谢谢!
推荐答案
将google-services
插件升级到版本4.0.1
可以解决此问题.
Upgrading the google-services
plugin to version 4.0.1
fixed the issue.
从Firebase sdk更改日志页面: https://firebase.google.com/support/release-notes/android
From the Firebase sdk changelog page: https://firebase.google.com/support/release-notes/android
换句话说,更改此内容:
In other words, change this:
classpath 'com.google.gms:google-services:4.0.0'
对此:
classpath 'com.google.gms:google-services:4.0.1'
这篇关于Android库中的Firebase依赖项:无法在空对象上调用方法get()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!