27 4月 2011

Maven Android Plugin

 

主要是參考 sonatype的reference - Android Application Development with Maven

1. Maven android sdk deployer
Android SDK的安裝就不在這篇記錄了,直接跳到maven android sdk deployer安裝,先連到https://github.com/mosabua/maven-android-sdk-deployer/,按下Download後自行解壓縮。

Github - Maven android sdk deployer

 

進入解壓縮後的目錄執行

mvn install

正常的話可以看到類似下列的結果
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Maven Android SDK Deployer ........................ SUCCESS [0.598s]
[INFO] Android Platforms ................................. SUCCESS [0.007s]
[INFO] Android Platform 1.5 API 3 ........................ SUCCESS [0.336s]
[INFO] Android Platform 1.6 API 4 ........................ SUCCESS [0.034s]
[INFO] Android Platform 2.1 API 7 ........................ SUCCESS [0.022s]
[INFO] Android Platform 2.2 API 8 ........................ SUCCESS [0.016s]
[INFO] Android Platform 2.3 API 9 ........................ SUCCESS [0.033s]
[INFO] Android Platform 2.3.3 API 10 ..................... SUCCESS [0.019s]
[INFO] Android Platform 3.0 API 11 ....................... SUCCESS [0.037s]
[INFO] Android Add-Ons ................................... SUCCESS [0.011s]
[INFO] Android Add-On Google Platform 1.5 API 3 .......... SUCCESS [0.075s]
[INFO] Android Add-On Google Platform 1.6 API 4 .......... SUCCESS [0.034s]
[INFO] Android Add-On Google Platform 2.1 API 7 .......... SUCCESS [0.021s]
[INFO] Android Add-On Google Platform 2.2 API 8 .......... SUCCESS [0.027s]
[INFO] Android Add-On Google Platform 2.3 API 9 .......... SUCCESS [0.032s]
[INFO] Android Add-On Google Platform 2.3.3 API 10 ....... SUCCESS [0.028s]
[INFO] Android Add-On Google Platform 3.0 API 11 ......... SUCCESS [0.022s]
[INFO] Android Extras .................................... SUCCESS [0.012s]
[INFO] Android Compatibility Extra V4 .................... SUCCESS [0.016s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.922s
[INFO] Finished at: Wed Apr 27 17:28:29 CST 2011
[INFO] Final Memory: 4M/528M
[INFO] ------------------------------------------------------------------------
如果有特定的Platform或Add-On失敗的話,請確認在安裝AVD時是否有把所有的platform與add-on裝上。
其實全裝才有點不正常吧....
所以也可以改用指定profile的方式安裝
mvn install -P 2.3.3
 
可用的profile有1.5, 1.6, 2.1, 2.2, 2.3, 2.3.3, 3.0,就看本身AVD有裝哪些囉

2. pom.xml修改

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>Best1</groupId>
 <artifactId>Best1</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>apk</packaging>
 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 </properties>

 

<build> <finalName>best</finalName> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>maven-android-plugin</artifactId> <version>2.9.0-beta-4</version> <configuration> <sdk> <platform>10</platform> </sdk> <emulator> <avd>Android233</avd> <wait>10000</wait> <!--<options>-no-skin</options>--> </emulator> <deleteConflictingFiles>true</deleteConflictingFiles> </configuration> <extensions>true</extensions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>com.google.android</groupId> <artifactId>android</artifactId> <version>2.3.3</version> <scope>provided</scope> </dependency> </dependencies> </project>

再來就可以執行mvn android:emulator-start, mvn android:deploy來測試程式囉

 

沒有留言: