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]
Your APK or Android App Bundle file can contain just one AndroidManifest. xml file, but your Android Studio project may contain several—provided by the main source set, build variants, and imported libraries.
Metadata is data that describes other data to inform other applications how to use the data itself. Android usage: Intents are great example for that - If you want to pass data in intents it has to be primitive because Android only have pre-build metadata about those kind of objects.
xml file in the directory structure. Android Manifest usually contains pre-defined or static information which is then used to run the app. However, Android toolchain provides customization by allowing you to specify dynamic information through variable declaration, generally referred as Android Manifest placeholders.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With