Skip to content

Instantly share code, notes, and snippets.

@cdsap
Last active January 7, 2021 17:59
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save cdsap/19e277b8597b8b39ebc0 to your computer and use it in GitHub Desktop.
Save cdsap/19e277b8597b8b39ebc0 to your computer and use it in GitHub Desktop.
Example ManifestPlaceHolder
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapplication" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MyActivity"
android:label="${label}" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="${mapKey}" />
</application>
</manifest>
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.myapplication"
minSdkVersion 15
targetSdkVersion 20
versionCode 1
versionName "1.0"
manifestPlaceholders = [label: "defaultName"]
manifestPlaceholders = [mapKey: "your_debug_key"]
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
manifestPlaceholders = [mapKey: "your_release_key"]
}
}
productFlavors {
flavor1 {
manifestPlaceholders = [label: "flavor1"]
}
flavor2 {
manifestPlaceholders = [label: "flavor2"]
}
flavor3 {
manifestPlaceholders = [label: "flavor3"]
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
@cdunkel
Copy link

cdunkel commented Nov 5, 2015

Can you provide more information about what the result would be for the different build types and flavors? For example, do the label placeholders in the different flavors override the one specified in defaultConfig? What if I specified a placeholder for label in the release buildType? Would that get overridden by the flavors, or will the buildType placeholder always take precedence?

I ask all this because I'm trying to do something similar to what you have laid out in code, but I'm having a lot of trouble understanding how to get manifestPlaceholders to work the way I want.

Thanks.

@zhEdward
Copy link

use gradle2.6 this segment dones't work

@baole
Copy link

baole commented Nov 10, 2016

@zhEdward, in newer version, manifestPlaceholders is a map. So you should use it as folllowing

manifestPlaceholders = [label: "defaultName", mapKey: "your_debug_key"]

@zhEdward
Copy link

zhEdward commented Mar 1, 2017

@baole yes it's thanks :)

@JimVanG
Copy link

JimVanG commented Feb 6, 2018

Do manifestPlaceholders work when declared in a library module? So could i define the manifestPlaceholders in my library module and then would the consuming application would use those place holders?

@Barros9
Copy link

Barros9 commented Jan 7, 2021

Thanks, it was helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment