java - generateReleaseBuildConfig errors out in a library
问题描述
Android Studio project. I have two library modules, neither of them has any Java in it. I'm trying to suppress BuildConfig generation, so that there's no generated Java either. The gradle file for the first one goes:
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 3
targetSdkVersion 26
externalNativeBuild {
ndkBuild {
abiFilters "armeabi", "x86", "x86_64", "armeabi-v7a", "mips", "arm64-v8a"
targets "pad", "gif"
}
}
}
buildTypes {
release {
minifyEnabled false
}
debug {
jniDebuggable true
}
}
externalNativeBuild {
ndkBuild {
path file("src/main/jni/Android.mk")
}
}
}
dependencies {}
afterEvaluate {
generateReleaseBuildConfig.enabled = false
generateDebugBuildConfig.enabled = false
}
For the other:
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 3
targetSdkVersion 26
externalNativeBuild {
ndkBuild {
abiFilters "armeabi", "x86", "x86_64", "armeabi-v7a", "mips", "arm64-v8a"
}
}
}
buildTypes {
release {
minifyEnabled false
}
debug {
jniDebuggable true
}
}
externalNativeBuild {
ndkBuild {
path file("src/main/jni/Android.mk")
}
}
flavorDimensions 'Color'
productFlavors {
Blue {
dimension "Color"
externalNativeBuild {
ndkBuild {
cppFlags "-DBLUE"
}
}
}
Red {
dimension "Color"
externalNativeBuild {
ndkBuild {
cppFlags "-DRED"
}
}
}
}
}
dependencies {
implementation project(':Foo')
}
afterEvaluate {
generateReleaseBuildConfig.enabled = false
generateDebugBuildConfig.enabled = false
}
The first one worked for a while, no problem. The second one, I've created just today, and the Gradle sync on that fails:
A problem occurred configuring project ':LibBar'.
Could not get unknown property 'generateReleaseBuildConfig' for project ':LibBar' of type org.gradle.api.Project.
If I comment that line out, it complains about generateDebugBuildConfig
.
The second module depends on the first one, not sure if it matters.
Both have a manifest with nothing but package
.
What am I missing? I've tried cleaning the project, invalidating the caches. Gradle is the latest, so is Android Studio (just updated).
解决方案
The build system decorates the step name with the current build flavor. So it should be instead:
afterEvaluate {
generateBlueReleaseBuildConfig.enabled = false
generateBlueDebugBuildConfig.enabled = false
generateRedReleaseBuildConfig.enabled = false
generateRedDebugBuildConfig.enabled = false
}
推荐阅读
- typescript - 如何从 Array.prototype.reduce 更改返回类型?
- vba - VBA Word 宏在页脚中查找文本(已实现)并打印到文本文件(不太好用)
- c - 如何使用 SWIG wrap 在 Delphi 中使用 C 库
- r - 为什么我不能将 ggplot 图例框的背景颜色更改为白色?(其他颜色也可以)
- artifactory - 当用户在具有非 ASCII 字符的组中时,Artifactory 登录错误
- android - 如何使用 adb 在 Android 11 上触发 BroadcastReceiver?
- r - 在 map_df 函数中提取编码 UTF-8
- algorithm - 根据排名匹配球队中的球员
- python - 用于开发的 NetBox 插件安装
- google-sheets - googlesheets 上的月份函数