Jeffrey Blattman Jeffrey Blattman - 13 days ago 5
Android Question

android+gradle: different manifest meta-data per flavor

i would like to define a different

meta-data
manifest attribute depending on the product flavor. i tried to do this,

src/
main/
AndroidManifest.xml
prod/
AndroidManifest.xml
dev/
AndroidManifest.xml


the
main
manifest is complete, but the
prod
and
dev
versions are sparse and only contain the meta-data,

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.inventory"
android:versionCode="1"
android:versionName="1.0">

<meta-data android:name="analytics"
android:value="true"/>

</manifest>


it's my understanding that the flavor manifests will merge with the main. in my build.gradle, i do,

android {
productFlavors {
prod {
manifest.srcFile "prod/AndroidManifest.xml"
}
dev {
manifest.srcFile "dev/AndroidManifest.xml"
}
}
...
}


however, find i try to build "assembleProdDebug", i get this,

* What went wrong:
A problem occurred evaluating project ':Inventory'.
> No signature of method: org.gradle.api.java.archives.internal.DefaultManifest.srcFile() is applicable for argument types: (java.lang.String) values: [prod/AndroidManifest.xml]


thanks.

Answer

In your gradle file, you don't need to define the path to the manifest.

use:

productFlavors{
 prod {}
 dev{}
}

Verify that your directory structure is correct: a directory with the name of the flavour, for each flavour, under the src dir, and in each dir put the overriding manifest file.

Gradle will merge the files.

PS - if your meta-data tag is inside the application tag, you should also apply the application tag in the overriding manifest.

Comments