Search code examples
androidandroid-studioandroid-gradle-pluginandroid-version

Changes in Android BuildConfig.VERSION_NAME


Today I noticed that my debug build broke because the BuildConfig.VERSION_NAME now returns

1.6-debug

instead of

1.6

which is how it used to work before. Does anyone know if there's any documentation changes around this change?

If you're building the debug variant, it now appends -debug when you call BuildConfig.VERSION_NAME which is not the case before.
Regardless of whether it's a release or debug build, the value of BuildConfig.VERSION_NAME is always the same.

defaultConfig {
        applicationId "com.myapplication.id"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 106
        versionName "1.6"
        multiDexEnabled true //important
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

buildTypes {
    debug {
        minifyEnabled false
        useProguard false
        debuggable true
        buildConfigField "Boolean", "DEBUG_MODE", "true"
        versionNameSuffix "-debug"
    }
}

Solution

  • Remove versionNameSuffix "-debug" in your build.gradle file:

    buildTypes {
        debug {
            ....
            //versionNameSuffix "-debug"
        }
    }
    

    You can check the doc:

    Version name suffix. It is appended to the "base" version name when calculating the final version name for a variant.
    In case there are product flavor dimensions specified, the final version name suffix will contain the suffix from the default product flavor, followed by the suffix from product flavor of the first dimension, second dimension and so on.