【发布时间】:2018-11-06 22:50:53
【问题描述】:
我在将 firebase 依赖项添加到 android 库时遇到了构建问题。
我的设置如下
/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
在应用库插件 com.android.library 的模块中包含的任何 firebase-* 依赖项也会发生这种情况。
更多环境信息
$ ./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
欢迎提供任何线索或提示 :)
谢谢!
【问题讨论】:
-
你找到解决办法了吗?
-
没有。还没有。它看起来像一个竞争条件,因为从命令行有时有效,有时无效。但它在 Android Studio 中总是失败。
-
@NamiAlejandroSalimi 检查答案。将插件更新到 4.0.1 解决了这个问题。
标签: android firebase gradle android-gradle-plugin