Forked from saadfarooq/android_replace_in_manifest.gradle
Created
January 23, 2017 11:04
-
-
Save c3ph3us/161930e972067c774a94c36f119a0528 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 hidden or 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 hidden or 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