Skip to content

Commit

Permalink
Merge pull request #177 from chenenyu/dev
Browse files Browse the repository at this point in the history
try to fix build error in empty manifest
  • Loading branch information
chenenyu authored Jul 5, 2022
2 parents 17465fe + 2da800d commit 6571553
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ import org.gradle.api.Project

class ManifestTransformer {
static void transform(Project project, File input, File output) {
Node xml = new XmlParser().parse(input)
Node applicationNode = xml.get('application')[0]
applicationNode.appendNode('meta-data', ['android:name': project.name, 'android:value': 'com.chenenyu.router.moduleName'])
FileWriter fileWriter = new FileWriter(output)
XmlNodePrinter nodePrinter = new XmlNodePrinter(new PrintWriter(fileWriter))
nodePrinter.setPreserveWhitespace(true)
nodePrinter.print(xml)
Node manifest = new XmlParser().parse(input)
Node applicationNode = null
Object application = manifest.get('application')
if (application instanceof NodeList) {
if (application.isEmpty()) { // There is no `application` node in AndroidManifest.xml
applicationNode = manifest.appendNode("application", ['xmlns:android': 'http://schemas.android.com/apk/res/android'])
} else {
applicationNode = application.first()
}
applicationNode.appendNode('meta-data', ['android:name': project.name, 'android:value': 'com.chenenyu.router.moduleName'])
}
if (applicationNode != null) {
FileWriter fileWriter = new FileWriter(output)
XmlNodePrinter nodePrinter = new XmlNodePrinter(new PrintWriter(fileWriter))
nodePrinter.setPreserveWhitespace(true)
nodePrinter.print(manifest)
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android.useAndroidX=true
# apply router plugin
applyRemotePlugin=false
# router gradle plugin version
PLUGIN_VERSION=1.8.1
PLUGIN_VERSION=1.8.2
# router library version
ROUTER_VERSION=1.8.0
# compiler library version
Expand Down

0 comments on commit 6571553

Please sign in to comment.