最近使用maven自動構建android的簽名apk包(配合hudson),遇到幾個問題跟你們分享下: java
一、使用maven-android-plugin能夠很容易實現自動構建,但基於命令行的方式有別與eclipse的打包方式 android
二、編譯時出現非法字符的錯誤 apache
1 |
*.java:[1,0] 非法字符: \65279 |
說明某些文件採用UTF-8的時候寫入了BOM的頭信息,eclipse採用jdt會自動處理這些頭信息但maven直接調用javac沒有那麼智能了,首先找找那些文件 vim
2 |
find -type f -name "*.java"|while read file;do [ "`head -c3 -- "$file"`"== $'\xef\xbb\xbf' ] && echo "found BOM in: $file";done |
使用vim自動去除bom api
三、打包是出現沒法簽名的狀況 dom
02 |
<groupId>org.apache.maven.plugins</groupId> |
03 |
<artifactId>maven-jarsigner-plugin</artifactId> |
04 |
<version>1.2</version> |
11 |
<phase>package</phase> |
12 |
<inherited>true</inherited> |
14 |
<archiveDirectory></archiveDirectory> |
16 |
<include>target/${artifactId}.apk</include> |
18 |
<keystore>${keyFilePath}</keystore> |
19 |
<storepass>${storePassword}</storepass> |
20 |
<keypass>${keyPassword}</keypass> |
21 |
<alias>${keyAlias}</alias> |
alias必須與生成簽名文件時的條目一致 eclipse
四、簽名以前必須保證apk生成的時候沒有使用debug簽名,否則會提示 maven
1 |
jarsigner: 沒法對 jar 進行簽名: java.util.zip.ZipException: invalid entry compressed size (expected 15331 but got 15809 bytes) |
必須定義maven的android插件信息 ide
03 |
<path>${env.ANDROID_HOME}</path> |
04 |
<platform>7</platform> |
09 |
<deleteConflictingFiles>true</deleteConflictingFiles> |
五、至此使用一條命令 mvn clean package就能夠自動編譯打包了 ui
下面是完整的配置
001 |
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
002 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
003 |
<modelVersion>4.0.0</modelVersion> |
004 |
<groupId>com.xxxx.gcl</groupId> |
005 |
<artifactId>xxxx</artifactId> |
006 |
<version>2.1.2</version> |
007 |
<packaging>apk</packaging> |
011 |
<groupId>com.google.android</groupId> |
012 |
<artifactId>android</artifactId> |
013 |
<version>2.1.2</version> |
014 |
<scope>provided</scope> |
017 |
<groupId>com.thoughtworks.xstream</groupId> |
018 |
<artifactId>xstream</artifactId> |
019 |
<version>1.3.1</version> |
022 |
<groupId>com.dom4j</groupId> |
023 |
<artifactId>dom4j</artifactId> |
024 |
<version>1.6.1</version> |
027 |
<groupId>commons-httpclient</groupId> |
028 |
<artifactId>commons-httpclient</artifactId> |
029 |
<version>3.1</version> |
032 |
<groupId>com.autonavi</groupId> |
033 |
<artifactId>mapapi</artifactId> |
034 |
<version>1.0</version> |
038 |
<finalName>${artifactId}</finalName> |
039 |
<sourceDirectory>src</sourceDirectory> |
043 |
com.jayway.maven.plugins.android.generation2 |
045 |
<artifactId>android-maven-plugin</artifactId> |
046 |
<version>3.1.1</version> |
049 |
<path>${env.ANDROID_HOME}</path> |
050 |
<platform>7</platform> |
055 |
<deleteConflictingFiles>true</deleteConflictingFiles> |
057 |
<extensions>true</extensions> |
058 |
<inherited>true</inherited> |
061 |
<artifactId>maven-compiler-plugin</artifactId> |
065 |
<encoding>UTF-8</encoding> |
069 |
<groupId>org.apache.maven.plugins</groupId> |
070 |
<artifactId>maven-jarsigner-plugin</artifactId> |
071 |
<version>1.2</version> |
078 |
<phase>package</phase> |
079 |
<inherited>true</inherited> |
081 |
<archiveDirectory></archiveDirectory> |
083 |
<include>target/${artifactId}.apk</include> |
085 |
<keystore>${keyFilePath}</keystore> |
086 |
<storepass>${storePassword}</storepass> |
087 |
<keypass>${keyPassword}</keypass> |
088 |
<alias>${keyAlias}</alias> |
099 |
<activeByDefault>true</activeByDefault> |
102 |
<keyFilePath>xxxxxxx</keyFilePath> |
103 |
<storePassword>xxxx</storePassword> |
104 |
<keyPassword>xxxx</keyPassword> |
105 |
<keyAlias>xxxxx</keyAlias> |
111 |
<keyFilePath>xxxxx</keyFilePath> |
112 |
<storePassword>xxxxx</storePassword> |
113 |
<keyPassword>xxxx</keyPassword> |
114 |
<keyAlias>xxxxxx</keyAlias> |