android - 错误 :(47, 0) 无法为 com.android.build.gradle.AppExtension 类型的对象获取未知属性 'IS_CI_BUILD'

标签 android android-studio gradle android-gradle-plugin

在执行 rm -rf ~/.gradlerm -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 值,但每当我将它更改为 truefalse 并尝试运行应用程序时,会弹出一个编辑配置对话框,我可以在其中我不太确定该怎么做。

最佳答案

嗯,事实证明现在我有问题的 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/

相关文章:

android - 喷气背包组成。导航 IllegalStateException

c# - Uri 类的反射 GetValue 失败

android - 如何在 Fragment - Android 中使用 PlaceAutoCompleteFragment 小部件?

java - 按需在 Gradle 中制作 NON-FAT jar

build - 无论有没有分析方面的内容,如何使用gradle构建项目?

java - Android 应用服务器的行业标准是什么?

Android react-native-push-notification onNotification 当应用程序在后台并单击通知时未调用?

android - Android Studio 中的 "Subversion command line client version is too old"错误

java - 如何从 Activity A 中的 EditText 获取多个整数值以在 Activity B 的 TextView 中显示最小值和最大值?

android - 如何找到用于手动测试的android应用程序的代码覆盖率?