Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Manifest placeholders for different build types

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

like image 780
Billda Avatar asked Jun 26 '14 07:06

Billda


People also ask

What is manifest placeholder?

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.

How do you use a manifest placeholder?

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.

What should be included in Android manifest?

A manifest can contain only one application node. It uses attributes to specify the metadata for your application (including its title, icon, and theme).

What is contained within Android manifest file?

The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.


2 Answers

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.

like image 198
Mike Cwiklinski Avatar answered Sep 23 '22 18:09

Mike Cwiklinski


Starting today with gradle plugin 0.13.0 is already working.

like image 32
OriolJ Avatar answered Sep 20 '22 18:09

OriolJ