I am very hyped about the new possibility of manifest placeholders in Gradle + Android Build. I've found in the gradle documentation that I can specify my own placeholders like this:
productFlavors {
free {
}
pro {
manifestPlaceholders = [ activityLabel:"proName" ]
}
}
But I would like to have one placeholder dependent on build type and not on product flavors. When I insert that placeholder specification into build type settings it takes no effect. Do you know how to achieve this? Because it seems to me stupid have three build types and three flavors associated with it. Thanks
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.
Inject build variables into the manifest You can then insert one of the placeholders into the manifest file as an attribute value like this: <intent-filter ... > By default, the build tools also provide your app's application ID in the ${applicationId} placeholder.
A manifest can contain only one application node. It uses attributes to specify the metadata for your application (including its title, icon, and theme).
The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.
This is my solution for different product flavours:
build.gradle:
productFlavors {
normal {
applicationId "mobi.cwiklinski.urc"
buildConfigField "String", "providerAuthority", "\"mobi.cwiklinski.urc.provider\""
resValue "string", "authorities", "mobi.cwiklinski.urc.provider"
}
adfree {
applicationId "mobi.cwiklinski.urc.adfree"
buildConfigField "String", "providerAuthority", "\"mobi.cwiklinski.urc.adfree.provider\""
resValue "string", "authorities", "mobi.cwiklinski.urc.adfree.provider"
}
}
AndroidManifest.xml
<provider
android:name="mobi.cwiklinski.urc.provider.AppProvider"
android:authorities="@string/authorities"
android:exported="true"
android:label="@string/app_name"
android:syncable="true"
android:writePermission="mobi.cwiklinski.urc.permission.USE_PROVIDER" />
And that's all - in different product flavours you will get different resource value.
Starting today with gradle plugin 0.13.0 is already working.
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