2

I've made 4 different flavours of the same app and published all of them on Play Store as free apps.

Now I'm making a paid version for each of them, and in order to achieve that I've created 2 new flavours: free and paid, and these flavours have a different dimension to the one of the 4 apps. The 4 apps have the "version" dimension and the free/paid flavours have the "mode" dimension.

What I'm trying to figure out how to do is to set different version codes and names to each version/mode pair, e.g.: flavourAFree -> versionCode 1 / flavourAPaid -> versionCode 2

Here's my code:

flavorDimensions "version", "mode"

productFlavors {
    flavourA {
        dimension "version"
        ...
    }

    flavourB {
        dimension "version"
        ...
    }

    flavourC {
        dimension "version"
        ...
    }

    flavourD {
        dimension "version"
        ...
    }

    free {
        dimension "mode"
    }

    paid {
        dimension "mode"
    }
}

An example of what I'm trying to achieve (not exactly these values):

flavourAFree {
    versionCode 1
    versionName "1.0"
}

flavourAPaid {
    versionCode 4
    versionName "2020.2.0"
}

When I try syncing my Gradle script I get the following error:

A problem occurred configuring project ':app'. Flavor 'flavourA' has no flavor dimension.

Is there a way to do what I'm trying to do?

92AlanC
  • 1,327
  • 2
  • 14
  • 33

1 Answers1

0

What you need to do is described in this android article

android {
    defaultConfig {
        versionCode 13
        versionName "2020.2"

    }

flavorDimensions "version", "mode"

productFlavors {
    flavourA {
        dimension "version"
        ...
    }

    flavourB {
        dimension "version"
        ...
    }

    flavourC {
        dimension "version"
        ...
    }

    flavourD {
        dimension "version"
        ...
    }

    free {
        dimension "mode"
        versionCode android.defaultConfig.versionCode
        versionName android.defaultConfig.versionName + ".3"
    }

    paid {
        dimension "mode"
        versionCode android.defaultConfig.versionCode - 12
        versionName android.defaultConfig.versionName + ".0"
    }
}

I don't know if it's what you're looking for, but it'll create:

  • flavourAFree with versionCode = 13 and versionName = "2020.2.3"
  • flavourBFree with versionCode = 13 and versionName = "2020.2.3"
  • flavourAPaid with versionCode = 1 and versionName = "2020.2.0"
  • flavourBPaid with versionCode = 1 and versionName = "2020.2.0"

For more information I recommend this article

Biscuit
  • 4,840
  • 4
  • 26
  • 54
  • Actually what I'm looking for is a specific version for each version/mode paid. I've updated the example on my question for more clarity – 92AlanC May 04 '20 at 12:25