androidgradleandroid-gradle-pluginandroid-productflavorspackage-name

How to have multiple ApplicationIds for the same product flavor?


We have a white label application with a handful of flavors for different clients. A new client has come on that wants the ability to publish the app through their own developer account. However, prior to release, we need to test the app through our internal test track and verify that the prod environment works (such as billing).

When we got started with development, we created a new product flavor, "com.business.android.product". Now that we are getting close to release, we need a different package name, "com.example.android.thing". My question is, how can we have two package names for the same flavor (i.e. using the same code in the /product source folder)?

Here is an example of our flavor and build type setup

productFlavors {
    prod1 {
        applicationId "com.business.android"
        buildConfigField 'boolean', 'REPORT_CRASHES', "true"
    }
    prod2 {
        applicationId "com.business.android.product2"
        buildConfigField 'boolean', 'REPORT_CRASHES', "true"
    }
    prod3 {
        applicationId "com.business.android.product3"
        buildConfigField 'boolean', 'REPORT_CRASHES', "true"
        def flavor = "spg"
    }
    prod4 {
        applicationId "com.company.android.product4"
        buildConfigField 'boolean', 'REPORT_CRASHES', "true"
    }

    /* Need a way to have all the code in /prod4 flavor source folder but with
     * a very different applicationId - ex. somebusiness.android.product4
     *
     */
}

buildTypes {
    debug {
        debuggable true
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.KEY
        def buildType = "debug"
        def targetEnvironment = "production"
        buildConfigField "boolean", "PRODUCTION_ENV", "true"
    }

    debugTst {
        minifyEnabled false
        debuggable true
        signingConfig signingConfigs.KEY
        def buildType = "debug"
        buildConfigField "boolean", "PRODUCTION_ENV", "false"
    }

    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.KEY
        def buildType = "release"
        buildConfigField "boolean", "PRODUCTION_ENV", "true"
    }

    releaseTst {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.KEY
        def buildType = "release"
        buildConfigField "boolean", "PRODUCTION_ENV", "false"
    }
}

Solution

  • This issue can be resolved by performing the follow:

    sourceSets {
        prod4Ext.java.srcDirs += 'src/prod4/java'
        prod4Ext.res.srcDirs += 'src/prod4/res'
    }
    

    This will provide the prod4 flavor's source code and layouts to the newly created flavor prod4Ext.