buildConfigField fails because BuildConfig generation is switched off
Build Type contains custom BuildConfig fields, but the feature is disabledShort answer
Android Gradle plugin 8.0 stopped generating the BuildConfig class by default, so a buildConfigField has nowhere to go. Set buildFeatures { buildConfig = true } in each module that needs it, or switch the default back on in gradle.properties for the whole project.
Fix it fast
1Find out which cause you have
Check which version of the Android Gradle plugin the project uses, because the default changed at 8.0.
grep -rn "com.android" build.gradle* settings.gradle* gradle/libs.versions.toml2Match what you see, then jump to its fix
What does the error look like?
Build Type contains custom BuildConfig fields, but the feature is disabled
Cause 1 of 2
BuildConfig is off for this module
1Check
AGP 8.0 changed the default of android.defaults.buildfeatures.buildconfig from true to false. The DSL reference lists buildConfig under BuildFeatures with a default of false.
grep -n "buildFeatures\|buildConfig" app/build.gradle*2Fix
Enable the feature in the module that defines the field. Repeat it in every library module that uses buildConfigField.
// app/build.gradle.kts
android {
buildFeatures {
buildConfig = true
}
}3Verify
Sync and build; the generated BuildConfig class then contains your fields.
./gradlew :app:assembleDebugConfirmed by developer.android.com
Cause 2 of 2
Many modules need it and you want the old default back
1Check
The release notes name the flag android.defaults.buildfeatures.buildconfig. Setting it restores generation for every module that does not decide for itself.
cat gradle.properties2Fix
Add the flag to gradle.properties at the project root. Doing it per module is cleaner, because it keeps the build faster, which was the point of the new default.
android.defaults.buildfeatures.buildconfig=true3Verify
Run a build of every module.
./gradlew assembleDebugConfirmed by developer.android.com
How do I stop it coming back?
- Declare buildFeatures next to the code that needs it, so the dependency is visible in the module's build file.
- Read the AGP release notes' table of changed defaults before each major upgrade.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Mobile apps
BuildConfig is red or missing after a plugin upgrade
Cannot resolve symbol 'BuildConfig'
Since Android Gradle plugin 8.0 the BuildConfig class is no longer generated unless a module asks for it.
2 causes, each with a fixMobile apps
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile apps
Android Studio cannot pair the phone over Wi-Fi
The Pair devices over Wi-Fi dialog lists no device
Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.
4 causes, each with a fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fix