How to manage two different applicationId in productFlavors?

1.6k Views Asked by At

I need to manage two different client code in single project so i have used productFlavors and defined flavor for each client.

Now the question is source code base is same for both but need to define different applicationId like

  1. com.abc
  2. com.def.

How would I make flavor so that code remain same for both and appId different?

2

There are 2 best solutions below

2
On

add the code block set applicationId like below :

productFlavors {
        abc {
            resValue "string", "build_type", "Version " + defaultConfig.versionName
            applicationId "com.abc"
        }
        def {
            resValue "string", "build_type", "Version " + defaultConfig.versionName
            applicationId "com.def"
        }
0
On

Android will create main/ source set and directories for everything you want to share between all your build variants, so no need for creating new source set in your case.

And you could use applicationIdSuffix for different build variants,which is appended to the "base" application id when calculating the final application id for a variant.

For example:-

flavorDimensions "appMode"

productFlavors {

    free {
        dimension "appMode"
        applicationIdSuffix ".free" //the application id of 'free' is com.example.com.free
    }
    paid {
        dimension "appMode"
        applicationIdSuffix ".paid"//the application id of 'free' is com.example.com.paid
    }
}

The applicationIdSuffix will be appended to the package name(base application id), com.example.com is the package name in above example.