Search code examples
androidmanifestbuild.gradleandroid-productflavors

Android different packageName with flavors


I need to install 2 versions of my project (Production and Development). I need 2 apps. I'm trying to achive it by using flavors, but when I sign the apk, it always generate the same app, with the same packageName (com.company.project). I've tried removing the applicationId from the defaultConfig but it doesn't work neither.In the manifest, the package name is com.company.project.

Anyone knows how to do that?

This is the build.gradle

defaultConfig {
            multiDexEnabled true
            minSdkVersion 16
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
            applicationId "com.company.project"
    }    
    productFlavors {
                development {
                    applicationId
                    "com.company.project.DEV"
                    versionName "1.0-dev"
                    resValue "string", "app_name", "Project-Dev"                     
                }
                production {
                    applicationId
                    "com.company.project.PROD"
                    resValue "string", "app_name", "Project-Prod"
                    versionName "1.0-prod"                        
                }
            }

Solution

  • Finally I did it like this:

    def appName = 'AppName'
    productFlavors {
        devel {
            applicationIdSuffix ".devel"
            def buildId, appNameLabel
            buildId = androidApplicationId + '.devel' + androidVersionCode
            appNameLabel = appName + 'd' + androidVersionName
            buildConfigField "String", "BUILD_ID", '"' + buildId + '"'
            manifestPlaceholders = [app_name_label: appNameLabel, buildId: buildId]        }
    
        QA { 
            applicationIdSuffix ".qa"
            def buildId, appNameLabel
            buildId = androidApplicationId + '.qa' + androidVersionCode
            appNameLabel = appName + 'q' + androidVersionName
            buildConfigField "String", "BUILD_ID", '"' + buildId + '"'
            manifestPlaceholders = [app_name_label: appNameLabel, buildId: buildId]
        }
    
        pro {
            buildConfigField "String", "BUILD_ID", '"' + androidApplicationId + '"'
            manifestPlaceholders = [app_name_label: appName, buildId: androidApplicationId]
        }