In the new version of Android Studio (Flamingo | 2022.2.1 Canary 9) with the org.jetbrains.kotlin (1.8.0-Beta) plugin and 8.0.0-alpha09 gradle plugin, a new build suddenly gets this error:
Build Type ‘release’ contains custom BuildConfig fields, but the feature is disabled.
Is there a way to make this go away?
3
Answers
Answering my own question -- there is a quick solution. Try adding the following line to
gradle.properties
, and the problem should hopefully stop bothering you (for now):Or, per @Scott_AGP's answer, it may be better to add this to
build.gradle
instead of changinggradle.properties
:This issue is due to the deprecation of
buildConfigField
(from android.packageBuildConfig) as described in this commit.UPDATE 12/12/22:
Per a note from Roar Grønmo below, there is a newer way to sneak the timestamp into the
BuildConfig.java
file than the one I suggested back in 2014.To use this newer method, first delete any lines in your current
build.gradle
(orbuild.gradle.kts
) file that looks like:Instead, first add the following to the top of your
build.gradle.kts
:and outside of the
android { ... }
part ofbuild.config.kts
add this:You shouldn't have to make any new changes to your main codebase-- the timestamp can still be accessed in Kotlin like this:
That's it! Note this still requires the change to
gradle.properties
described above or you will see an Accessing value buildConfigFields in variant ____ has no effect as the feature buildConfig is disabled. warning.There may still be a better way to do this without using
BuildConfigField
, but if so, I don't know it. If anyone has a more permanent fix, please let me (us) know.adding
android.defaults.buildfeatures.buildconfig=true
to yourgradle.properties
would fix this.Avoid adding
android.defaults.buildfeatures.buildconfig=true
to yourgradle.properties
file because that property is deprecated in AGP 8.0 and is scheduled to be removed in AGP 9.0.Instead, add the following to the per-module
build.gradle
file for each module usingBuildConfig
: