在向android库添加firebase依赖项时,我遇到了构建问题。
我的设置如下
/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
您可以在this pastebin
中找到原始错误的完整堆栈跟踪 有趣的事情是module-lib
只包含占位符,空和无用的类。如果我从module-lib
中删除了firebase依赖项并将其移至module-app
,那么构建工作正常。
我没有使用Android Studio,因此这是纯粹的Gradle和/或插件 和/或依赖性问题。
另请注意
./gradlew clean // Always succeds
./gradlew build // Sometimes works with above error
./gradlew clean build // Always fails with above error
在应用库插件firebase-*
的模块中包含的任何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
任何线索或提示都非常受欢迎:)
谢谢!
答案 0 :(得分:43)
将google-services
插件升级到版本4.0.1
可以解决此问题。
从Firebase sdk更改日志页面:https://firebase.google.com/support/release-notes/android
换句话说,更改此内容:
classpath 'com.google.gms:google-services:4.0.0'
对此:
classpath 'com.google.gms:google-services:4.0.1'