ResourcesPlaceholders
Gradle plugin which adds support for ${placeholder} manifestPlaceholders in Android resource files
Installation
Add the following to your build.gradle
:
buildscript {
repositories {
// ...
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.github.timfreiheit:ResourcePlaceholdersPlugin:X.X.X'
}
}
apply plugin: 'com.android.application'
// Make sure to apply this plugin *after* the Android plugin
apply plugin: 'de.timfreiheit.resourceplaceholders.plugin'
Usage
A common use case is using the ${applicationId}
when defining App Shortcuts.
The android:targetPackage must be set statically and can not easily be used with different build variants or types.
Using placeholders the shortcuts.xml
file could look something like:
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut ...>
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.test.MainActivity"
android:targetPackage="${applicationId}"/>
</shortcut>
</shortcuts>
Register the file in your apps build.gradle
to the plugin:
resourcePlaceholders {
files = ['xml/shortcuts.xml']
}
Every file in which the placeholders should be supported must be listed. This improves incremental builds and avoid unnecessary work.