How do I change the AndroidManifest.xml file based on build variants?

You can save the string in build.gradle too:

productFlavors {
    app1 {
        applicationId "com.acme.app1"
        resValue "string", "my_app_key", "db-abc"
    }

    app2 {
        applicationId "com.schmoe.app2"
        resValue "string", "my_app_key", "db-def"
    }

    app3 {
        applicationId "com.yop.app3"
        resValue "string", "my_app_key", "db-ghi"
    }
}

And then use it like:

<data android:scheme="@string/my_app_key" />

You can do this the same way you would modify the app name, using a string resource. In your manifest, include:

<data android:scheme="@string/db_scheme" />

Next, you add resources folders for the various build types, and in each, place a custom copy of a resource file, say res/values/flavor.xml:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
    <string name="app_name">Customer 1 App</string>
    <string name="db_scheme">db-111111</string>
</resources>

This will allow you to have different API keys, schemes, app-names, icons, etc. for your various flavors.

Tags:

Android