0

I have problem with versioning Android application with multiple flavors and dimensions. Project is configured like this: Three dimensions:

flavorDimensions "company", "app", "server"

And multiple flavors:

productFlavors {
    company1 {
        applicationId "com.com1"
        dimension "company"
    }
    company {
        applicationId "com.com2"
        dimension "company"
    }
    app1 {
        applicationId "com.app1"
        dimension "app"
    }
    app2 {
        applicationId "com.app2"
        dimension "app"
    }
    sever1 {
        dimension "server"
    }
    server2 {
        dimension "server"
    }

To ignore some of the possible mixes, everything is done by doing setIgnore in gradle file

    variantFilter { variant ->
    def names = variant.flavors*.name
    if (names.contains("app1") && names.contains("sever2") ||
            names.contains("app1") && names.contains("sever1") ||
            names.contains("app2") && names.contains("company1") ||
            names.contains("company") && names.contains("server2")) {
        setIgnore(true)
    }
}

Everything is based on the Advanced Android Flavors series

So with that configuration, I do not know how to set different versions for different variants. Something like

company1app1 {
        versionCode 2
        versionName "1.0." + versionCode
}
company2app1 {
        versionCode 5
        versionName "1.1." + versionCode
}
company1app2 {
        versionCode 8
        versionName "1.0." + versionCode
}
company1app2 {
        versionCode 2
        versionName "1.0." + versionCode
}

Any solutions?

Jakub Anioła
  • 310
  • 3
  • 16

1 Answers1

1

A possible solution: in defaultConfig add lines

versionCode computeVersionCode()
versionName computeVersionName()

computeVersionCode() and computeVersionName() can be arbitrary functions, for example:

def computeVersionCode(){
    String flavor = getCurrentFlavor()
    if (flavor.startsWith("company1app1")){
        return 2
    } else if (flavor.startsWith("company2app1")){
        return 5
    } else if (flavor.startsWith("company1app2")){
        return 8
    } else if (flavor.startsWith("company2app2")){
        return 2
    } else {
        return 1
    }
}

getCurrentFlavor() is defined here https://stackoverflow.com/a/44183316/5312102

atarasenko
  • 1,768
  • 14
  • 19