Reputation: 22637
iI 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]
Upvotes: 21
Views: 11555
Reputation: 1774
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.
Upvotes: 25