Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

buildConfigField fails because BuildConfig generation is switched off

ErrorBuild Type contains custom BuildConfig fields, but the feature is disabled

Short 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.

  • Applies to Android Gradle plugin 8.x, Gradle 8.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.toml
  2. 2Match what you see, then jump to its fix

    1. 1The error appears right after upgrading the Android Gradle plugin to 8.0 or newer.BuildConfig is off for this moduleFix
    2. 2The same error shows up in several modules one after another.Many modules need it and you want the old default backFix

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:assembleDebug

Confirmed by developer.android.com

Did this fix it?

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.properties

2Fix

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=true

3Verify

Run a build of every module.

./gradlew assembleDebug

Confirmed by developer.android.com

Did this fix it?

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

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.