-
-
Save SwiftyWang/621bf306e7bfb4be5a471475ac8ea76c to your computer and use it in GitHub Desktop.
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
android.applicationVariants.all { variant -> | |
variant.outputs.all { output -> | |
output.processManifest.doLast { | |
def placeholders = variant.mergedFlavor.manifestPlaceholders; | |
if (placeholders == null || placeholders.isEmpty()) { | |
return | |
} | |
def manifestDirPath = manifestOutputDirectory.asFile.get() | |
String manifestMergerpath = "$manifestDirPath/AndroidManifest.xml" | |
def link = manifestDirPath.toString() | |
link = link.replace("merged_manifests","bundle_manifest") | |
def productFlavor = link.split("/bundle_manifest/").getAt(1) | |
def upper = productFlavor.capitalize() | |
productFlavor = "process$upper" +"Manifest" | |
link = link + "/$productFlavor/bundle-manifest/AndroidManifest.xml" | |
writeManifest(manifestMergerpath,placeholders) | |
writeManifest(link,placeholders) | |
} | |
} | |
} | |
def writeManifest(String manifestPath,HashMap placeholders){ | |
def manifestContent = file(manifestPath).getText() | |
placeholders.each { key, value -> | |
if(key.equals("deepLinkPlaceholder")) { | |
Pattern pattern = Pattern.compile(Pattern.quote("deepLinkPlaceholder"), Pattern.DOTALL); | |
manifestContent = pattern.matcher(manifestContent).replaceAll(value); | |
} | |
} | |
file(manifestPath).write(manifestContent) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment