</p>
因为新的Gradle有Instant Run功能, 一些旧的代码不能正确运行, 此功能可用于动态替换一些占位符的内容.
参考: http://stackoverflow.com/questions/36874191/editing-androidmanifest-xml-in-gradle-task-processmanifest-dolast-has-no-effect
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
output.processManifest.doLast {
if(!rootProject.ext.enableThinker) {
[output.processManifest.manifestOutputFile,
output.processManifest.instantRunManifestOutputFile
].forEach({ File manifestOutFile ->
if (manifestOutFile.exists()) {
def newFileContents = manifestOutFile.getText('UTF-8').replace(
“\"xxxxApplication\"", “\"xxxxApplicationDev\"")
manifestOutFile.write(newFileContents, 'UTF-8')
println "*************** 更新AndroidManifest ********" + manifestOutFile
}
})
}
}
}
}
</body></html>
转载请注明:WebLogic Android 博客 » Android Gradle编译任务动态修改AndroidManifest的内容