What should be the package name in main/AndroidManifest.xml when dealing with product flavors?

565 Views Asked by At

I have two product flavors in my build.gradle which are as follows:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.2"
    aaptOptions.setProperty("cruncherEnabled", false)

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 16
        applicationId "com.example.app"
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    def final myApplicationId = 'com.example.app'
    def final appName = 'app'

    productFlavors {
        dev {

            resValue "string", "app_name", appName
            resValue "string", "APIURL", "http://prod.example.com/"
        }
        production {

            resValue "string", "app_name", appName
            resValue "string", "APIURL", "http://test.example.com/"
        }
    }
    buildTypes{
        dtest {
            applicationIdSuffix ".dev"
        }
        dprod{

        }
    }
}



dependencies {
    compile()
    few libraries
}

my dev/AndroidManifest.xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app.dev"
    android:installLocation="auto"
    android:versionCode="3"
    android:versionName="3.1">

</manifest>

and my production/AndroidManifest.xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app"
    android:installLocation="auto"
    android:versionCode="3"
    android:versionName="3.1">

</manifest>

my main/AndroidManifest.xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app"
    android:installLocation="auto"
    android:versionCode="3"
    android:versionName="3.1">
    <application>
          <activity list.. </activity>
    </application>
</manifest>

I want to install dev and production flavor in the same device, but I am not able to change the package name even when I have set different applicationId. I suspect package name that I mentioned in main manifest is overriding the applicationId from build.gradle in some way or another. I'd appreciate if someone points me in right direction. Thanks.

1

There are 1 best solutions below

12
On

Rather than setting that in productFlavors, add that in buildTypes

Use

buildTypes {
    debug {
        applicationIdSuffix ".dev"
        // Rest of the code block
    }

    release {
        // your code block
    }
}

Update

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.2"
    aaptOptions.setProperty("cruncherEnabled", false)

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 16
        applicationId "com.example.app"
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    buildTypes {
        debug{
            applicationIdSuffix ".dev"
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    productFlavors {
        dev {

            resValue "string", "app_name", appName
            resValue "string", "APIURL", "http://prod.example.com/"
        }
        production {

            resValue "string", "app_name", appName
            resValue "string", "APIURL", "http://test.example.com/"
        }
    }
}



dependencies {
    compile()
    few libraries
}