import groovy.util.slurpersupport.GPathResult def replaceManifest() { GPathResult androidManifest = new XmlSlurper().parse("AndroidManifest.xml") String versionName = androidManifest['@android:versionName'] versionName += ' beta' androidManifest.setProperty('@android:versionName', versionName + "") groovy.xml.XmlUtil.serialize(androidManifest, new PrintWriter(new File("AndroidManifest.xml"))) println "------groovy.xml.XmlUtil.serialize AndroidManifest end-------" }
buildNumber:007
------version name with suffix-------
AndroidManifest.xml,android:versionName:2.0.0
[Fatal Error] :2:183: The value of the attribute "prefix="xmlns",localpart="tag0",rawname="xmlns:tag0"" is invalid. Prefixed namespace bindings may not be empty.
ERROR: 'The value of the attribute "prefix="xmlns",localpart="tag0",rawname="xmlns:tag0"" is invalid. Prefixed namespace bindings may not be empty.'
Caught: groovy.lang.GroovyRuntimeException: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 183; The value of the attribute "prefix="xmlns",localpart="tag0",rawname="xmlns:tag0"" is invalid. Prefixed namespace bindings may not be empty.
groovy.lang.GroovyRuntimeException: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 183; The value of the attribute "prefix="xmlns",localpart="tag0",rawname="xmlns:tag0"" is invalid. Prefixed namespace bindings may not be empty.
at build_jenkins.replaceManifest(build_jenkins.groovy:52)
at build_jenkins.run(build_jenkins.groovy:9)
Build step 'Execute Groovy script' marked build as failure
Archiving artifacts
Email was triggered for: Failure - Any
Sending email for trigger: Failure - Any
An attempt to send an e-mail to empty list of recipients, ignored.
Finished: FAILURE
在jenkins服务器上,编译android项目,其中要动态修改其中的versionName,编译的时候出错了。
进行排查,对setProperty打印日志,发现设置失败。
经过对比分析,发现groovy版本是1.8.6导致,升级到2.4.7最新版本后问题解决。
初步分析,应该是1.8.6中对manifest中有些语法是不支持导致。