james04
james04

Reputation: 1920

Gradle applicationId with flavors for Android

I want to upload my application in the Google Play store but before it goes live i want to test it. There is a testing mode in the app and i want the production applicationId to be like

com.company.product

but i want also to have 2 flavours for testing like

com.company.product.alpha
&&
com.company.product.beta

How should my app build.gradle be like?

android {
    compileSdkVersion 30
    defaultConfig {
        applicationId "com.company"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  
        ....

flavorDimensions "version"
    productFlavors {
        product {
            dimension "version"
            applicationIdSuffix ".product"
            versionCode 1
            versionName "1.0"
        }

        alpha {
            dimension "version"
            applicationIdSuffix ".product.alpha"
            versionCode 1
            versionName "1.0"
        }
     
        beta {
            dimension "version"
            applicationIdSuffix ".product.beta"
            versionCode 1
            versionName "1.0"
        }
    }


.....Or i suppose to have it like??

android {
    compileSdkVersion 30
    defaultConfig {
        applicationId "com.company.product"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  
        ....

flavorDimensions "version"
    productFlavors {

        alpha {
            dimension "version"
            applicationIdSuffix ".alpha"
            versionCode 1
            versionName "1.0"
        }
     
        beta {
            dimension "version"
            applicationIdSuffix ".beta"
            versionCode 1
            versionName "1.0"
        }
    }


Upvotes: 0

Views: 495

Answers (1)

ziselos
ziselos

Reputation: 524

You can do something like this:

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
    applicationId "com.company.product"
    minSdkVersion 21
    targetSdkVersion 30
    flavorDimensions "application"
    versionCode 1
    versionName "1.0.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

productFlavors {
    alpha {
        dimension "application"
        applicationIdSuffix ".alpha"
        versionNameSuffix "-alpha"
        buildConfigField "String", "FLAVOR_TYPE", '"alpha"'
    }
    beta {
        dimension "application"
        applicationIdSuffix ".beta"
        versionNameSuffix "-beta"
        buildConfigField "String", "FLAVOR_TYPE", '"beta"'
    }
    production {
        dimension "application"
        applicationIdSuffix ""
        versionNameSuffix ""
        buildConfigField "String", "FLAVOR_TYPE", '"production"'
    }
}

Set applicationIdSuffix and versionNameSuffix for each flavour and keep empty for production one. In that way you can distribute com.company.product.alpha and com.company.product.beta for alpha and beta flavours.

Upvotes: 1

Related Questions