Gradle versionName and versionCode do not work after update 3.0

    flavorDimensions "app"
    productFlavors {
        dev {
            resValue "string", "base_url", "http://mydevurl/"
            dimension "app"
        }
        prod {
            resValue "string", "base_url", "http://myprodurl/"
            dimension "app"
        }
    }
    applicationVariants.all { variant ->
        def flavor = variant.mergedFlavor
        def versionName
        if (variant.buildType.isDebuggable()) {
            versionName = "debug_0.1.1"
        }else{
            versionName = "0.1.1"
        }
        flavor.versionName = versionName
        flavor.versionCode = 50
    }

Above gradle, the setup worked fine until gradle 3.0. Could not find anything related to the site. How to manage this dynamic version control based on this new change flavorDimension?

+4
source share
1 answer

You can dynamically set versionCode and versionName using the 3.0 Android gradle module using VariantOutput.setVersionCodeOverride () and VariantOutput.setVersionNameOverride ().

For your project, it looks something like this:

applicationVariants.all { variant ->
    def flavor = variant.mergedFlavor
    def versionName
    if (variant.buildType.isDebuggable()) {
        versionName = "debug_0.1.1"
    }else{
        versionName = "0.1.1"
    }
    flavor.versionName = versionName
    flavor.versionCode = 50
    variant.outputs.all { output ->
        output.setVersionNameOverride(versionName)
        output.setVersionCodeOverride(50)
    }       
}

link: https://issuetracker.google.com/issues/63785806#comment6

+8
source

Source: https://habr.com/ru/post/1688338/


All Articles