最近使用maven自动构建android的签名apk包(配合hudson),遇到几个问题跟大家分享下:
1、使用maven-android-plugin可以很容易实现自动构建,但基于命令行的方式有别与eclipse的打包方式
2、编译时出现非法字符的错误
*.java:[1,0] 非法字符: \65279
说明某些文件采用UTF-8的时候写入了BOM的头信息,eclipse采用jdt会自动处理这些头信息但maven直接调用javac没有那么智能了,首先找找那些文件
#查找BOM
find -type f -name "*.java"|while read file;do [ "`head -c3 -- "$file"`" == $'\xef\xbb\xbf' ] && echo "found BOM in: $file";done
使用vim自动去除bom
去掉utf-8 BOM
:set nobomb
3、打包是出现无法签名的情况
org.apache.maven.plugins
maven-jarsigner-plugin
1.2
signing
sign
package
true
target/${artifactId}.apk
${keyFilePath}
${storePassword}
${keyPassword}
${keyAlias}
alias必须与生成签名文件时的条目一致
4、签名之前必须保证apk生成的时候没有使用debug签名,不然会提示
jarsigner: 无法对 jar 进行签名: java.util.zip.ZipException: invalid entry compressed size (expected 15331 but got 15809 bytes)
必须定义maven的android插件信息
${env.ANDROID_HOME}
7
false
true
5、至此使用一条命令 mvn clean package就可以自动编译打包了
下面是完整的配置
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.xxxx.gcl
xxxx
2.1.2
apk
xxxxxx
com.google.android
android
2.1.2
provided
com.thoughtworks.xstream
xstream
1.3.1
com.dom4j
dom4j
1.6.1
commons-httpclient
commons-httpclient
3.1
com.autonavi
mapapi
1.0
${artifactId}
src
com.jayway.maven.plugins.android.generation2
android-maven-plugin
3.1.1
${env.ANDROID_HOME}
7
false
true
true
true
maven-compiler-plugin
1.6
1.6
UTF-8
org.apache.maven.plugins
maven-jarsigner-plugin
1.2
signing
sign
package
true
target/${artifactId}.apk
${keyFilePath}
${storePassword}
${keyPassword}
${keyAlias}
local
true
xxxxxxx
xxxx
xxxx
xxxxx
dev
xxxxx
xxxxx
xxxx
xxxxxx