BuildConfig is red or missing after a plugin upgrade
Cannot resolve symbol 'BuildConfig'Short answer
Since Android Gradle plugin 8.0 the BuildConfig class is no longer generated unless a module asks for it. Turn on buildFeatures.buildConfig in the module that reads BuildConfig, or restore the old default for every module with the android.defaults.buildfeatures.buildconfig property, then sync.
Fix it fast
1Find out which cause you have
Check whether the module that uses BuildConfig turns generation on. Search every build file for the flag.
grep -rn "buildConfig" --include=build.gradle --include=build.gradle.kts --include=gradle.properties .2Match what you see, then jump to its fix
- 1
The project built before upgrading to AGP 8 or newer, and the error covers only the BuildConfig classBuildConfig generation is off in this moduleFix - 2
The app compiles, while a library or feature module still reports the symbol as unresolvedOnly one module was fixed, but several modules read their own BuildConfigFix
- 1
What does the error look like?
Cannot resolve symbol 'BuildConfig'
Cause 1 of 2
BuildConfig generation is off in this module
1Check
AGP 8.0 changed the default of buildConfig from true to false, and the DSL reference gives the default as false. A module that never sets it gets no class.
grep -n "buildFeatures" -A3 app/build.gradle app/build.gradle.kts2Fix
Enable it in the module that needs the class. This also generates fields you declare with buildConfigField.
// build.gradle.kts
android {
buildFeatures {
buildConfig = true
}
}3Verify
Sync, then build the module and look for the class in the module's build output.
./gradlew :app:assembleDebug
find app/build -name BuildConfig.javaConfirmed by developer.android.com
Cause 2 of 2
Only one module was fixed, but several modules read their own BuildConfig
1Check
The release notes say to specify the option in the projects where you need it, so the flag is set per module, not once for the build.
grep -rLn "buildConfig = true" --include=build.gradle.kts .2Fix
Add buildFeatures { buildConfig = true } to every module that reads BuildConfig. For an older project that relied on the old default everywhere, set the global property in gradle.properties at the root.
# gradle.properties
android.defaults.buildfeatures.buildconfig=true3Verify
Sync and build the whole project.
./gradlew assembleDebugConfirmed by developer.android.com
How do I stop it coming back?
- After every AGP upgrade, read the release notes list of changed defaults before you debug unresolved symbols.
- Prefer enabling buildConfig only in the modules that need it; the default was changed to keep builds faster.
- Keep the flag in each module's build file, not in a copied snippet that nobody remembers.
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
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 fixMobile apps
adb tcpip 5555 fails because no device is found
adb: more than one device/emulator
adb tcpip only works while the device is attached and listed by adb, because it tells the phone to start listening on port 5555.
4 causes, each with a fix