在执行 rm -rf ~/.gradle
和 rm -rf ~/.gradle/wrapper/dists
之后(为了防止我的应用应用缓存某些第三方库的版本)我无法再构建我的应用程序,因为行
buildTypes.each {
it.buildConfigField 'boolean', 'IS_CI_BUILD', IS_CI_BUILD
}
导致这个错误:
Error:(47, 0) Could not get unknown property 'IS_CI_BUILD' for object of type com.android.build.gradle.AppExtension.
可能是什么原因?来自 this answer我推断我的 IS_CI_BUILD 属性应该是一个 bool 值,但每当我将它更改为 true
或 false
并尝试运行应用程序时,会弹出一个编辑配置对话框,我可以在其中我不太确定该怎么做。
最佳答案
嗯,事实证明现在我有问题的 build.gradle 行需要看起来像这样:
buildTypes.each {
it.buildConfigField 'boolean', 'IS_CI_BUILD', 'Boolean.parseBoolean("true")'
}
我刚刚打开我生成的 BuildConfig 类并注意到 gradle 有两种生成这些静态变量的方法,或者使用如下文字:
public static final boolean fabricEnabled = true;
或者像这样:public static final boolean DEBUG = Boolean.parseBoolean("true");
(更多信息 here)。
我的 IS_CI_BUILD 甚至不存在,所以我认为 AS 出于某种原因无法将其成功生成到 BuildConfig 类中,因此决定尝试第二种方法。成功了!
关于android - 错误 :(47, 0) 无法为 com.android.build.gradle.AppExtension 类型的对象获取未知属性 'IS_CI_BUILD',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45795444/