Forked from saadfarooq/android_replace_in_manifest.gradle
Last active
August 30, 2015 04:09
-
-
Save xbee/9ba00255bf7162c27848 to your computer and use it in GitHub Desktop.
Gradle function to replace a placeholder string in AndroidManifest.xml with productFlavor package name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
replaceInManifest = {variant, fromString, toString -> | |
def flavor = variant.productFlavors.get(0) | |
def buildtype = variant.buildType | |
def manifestFile = "$buildDir/manifests/${flavor.name}/${buildtype.name}/AndroidManifest.xml" | |
def updatedContent = new File(manifestFile).getText('UTF-8').replaceAll(fromString, toString) | |
new File(manifestFile).write(updatedContent, 'UTF-8') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
applicationVariants.all { variant -> | |
def flavor = variant.productFlavors.get(0) | |
def buildType = variant.buildType | |
variant.processManifest.doLast { | |
println '################# Adding Package Names to Manifest #######################' | |
replaceInManifest(variant, | |
'PACKAGE_NAME', | |
[flavor.packageName, buildType.packageNameSuffix].findAll().join()) // ignores null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment