androidgradleandroid-gradle-pluginandroid-configchangesandroid-build-type

Gradle - Android - add version code number as versionNameSuffix to debug buildTypes


I want to add the version code as a suffix of versionNameSuffix. Currently, I have:

    debug {
        versionNameSuffix ".debug"
    }

How can I have something like:

    debug {
        versionNameSuffix ".debug.versionCode"
    }

My version code is based on the productFlavors:

    productFlavors {
        free {
            versionCode 123
        }
    }

@Resolution: I move versionCode out from productFlavors to root level and use the accepted anwser to inject versionCode in versionNameSuffix


Solution

  • Create constant version code in your app build.gradle

    def versionCode = 1

    Then in your flavours

    debug {
        versionNameSuffix ".debug.${versionCode}”
    }
    

    Use the same version code in your defaultconfig also

    defaultConfig {
        versionCode ${versionCode}        
    }