- 首先在google.com搜索关键字“Android Maven”,可得到如下信息
-
- http://code.google.com/p/maven-android-plugin/
- 打开该网页,点击GettingStarted跳转到http://code.google.com/p/maven-android-plugin/wiki/GettingStarted 该页面
- 该连接下有一片整理得非常完善的文档,当然,全英文,本人英语没过B级阅读起来非常痛苦,此时此刻,非常羡慕那些看英文跟我看天朝文字一样流利的孩子
- http://rgladwell.github.com/m2e-android/ android maven
- http://code.google.com/p/maven-android-plugin/
- 可以看一下关于Android项目的介绍
- 众所周知,一般Android的项目可以使用Eclipse+adt来构建
- 单独使用ant也可以进行项目的打包编译集成,adt其实也是基于ant
- android-maven-plugin也是可以的
- 搭建环境
-
- 安装jdk 略过 我的是这个版本Java(TM) SE Runtime Environment (build 1.6.0_38-b05)
- 如需ubuntu 安装配置jdk的教程,请点击 http://hi.baidu.com/xingfukaixin/item/fa85176ad76dba34ad3e8364
- 安装Android-sdk
- 到Maven的官方下载最新版本的Maven
- 安装jdk 略过 我的是这个版本Java(TM) SE Runtime Environment (build 1.6.0_38-b05)
-
- 下载地址http://maven.apache.org/download.html
- 我下载的是 Maven 3.0.4
- 找个文件夹解压,并配置到系统的环境变量
- /home/wuyexiong/Android/tool/maven/apache-maven-3.0.4/bin 配置到/etc/environment
- ANDROID_HOME="/home/wuyexiong/Android/android-linux/adt-bundle-linux-x86_64/sdk"
- 想编译Android项目还差最后一部 ,用git把Maven AndroidSDK Deployer 项目载到本地
- 在此之前的环境都搭建完毕的前提下,进入该项目的跟目录
- 执行 mvn clean install 。 就会自动构建Android-maven的编译环境
- 中途会下载一些东西,检查你的sdk等等,稍作等候即可
-
[INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] Maven Android SDK Deployer ........................ SUCCESS [0.232s] [INFO] Android Platforms ................................. SUCCESS [0.007s] [INFO] Android Platform 1.5 API 3 ........................ SUCCESS [0.065s] [INFO] Android Platform 1.6 API 4 ........................ SUCCESS [0.013s] [INFO] Android Platform 2.1 API 7 ........................ SUCCESS [0.012s] [INFO] Android Platform 2.2 API 8 ........................ SUCCESS [0.013s] [INFO] Android Platform 2.3.3 API 10 ..................... SUCCESS [0.013s] [INFO] Android Platform 3.0 API 11 ....................... SUCCESS [0.028s] [INFO] Android Platform 3.1 API 12 ....................... SUCCESS [0.013s] [INFO] Android Platform 3.2 API 13 ....................... SUCCESS [0.013s] [INFO] Android Platform 4.0 API 14 ....................... SUCCESS [0.012s] [INFO] Android Platform 4.0.3 API 15 ..................... SUCCESS [0.013s] [INFO] Android Platform 4.1 API 16 ....................... SUCCESS [0.013s] [INFO] Android Platform 4.2 API 17 ....................... SUCCESS [0.012s] [INFO] Android Add-Ons ................................... SUCCESS [0.006s] [INFO] Android Add-On Google Platform 1.5 API 3 (Maps) ... SUCCESS [0.018s] [INFO] Android Add-On Google Platform 1.6 API 4 (Maps) ... SUCCESS [0.013s] [INFO] Android Add-On Google Platform 2.1 API 7 (Maps) ... SUCCESS [0.013s] [INFO] Android Add-On Google Platform 2.2 API 8 (Maps) ... SUCCESS [0.014s] [INFO] Android Add-On Google Platform 2.3.3 API 10 (Maps and USB) SUCCESS [0.017s] [INFO] Android Add-On Google Platform 3.0 API 11 (Maps) .. SUCCESS [0.013s] [INFO] Android Add-On Google Platform 3.1 API 12 (Maps and USB) SUCCESS [0.017s] [INFO] Android Add-On Google Platform 3.2 API 13 (Maps and USB) SUCCESS [0.016s] [INFO] Android Add-On Google Platform 4.0 API 14 (Maps and USB) SUCCESS [0.017s] [INFO] Android Add-On Google Platform 4.0.3 API 15 (Maps and USB) SUCCESS [0.018s] [INFO] Android Add-On Google Platform 4.1 API 16 (Maps and USB) SUCCESS [0.019s] [INFO] Android Add-On Google Platform 4.2 API 17 (Maps and USB) SUCCESS [0.018s] [INFO] Android Extras .................................... SUCCESS [0.009s] [INFO] Android Compatibility Extra V4 .................... SUCCESS [0.013s] [INFO] Android Compatibility Extra V7 Gridlayout Library . SUCCESS [1.999s] [INFO] Android Compatibility Extra V13 ................... SUCCESS [0.009s] [INFO] Android Google Analytics Extra .................... SUCCESS [0.009s] [INFO] Android Google AdMob Ads Extra .................... SUCCESS [0.009s] [INFO] Android Google Cloud Messaging Library Extra Parent SUCCESS [0.006s] [INFO] Android Google Cloud Messaging Client Library Extra SUCCESS [0.010s] [INFO] Android Google Cloud Messaging Server Library Extra SUCCESS [0.010s] [INFO] Android Google Play Services Extra ................ SUCCESS [0.460s] [INFO] Android Google Play Licensing Extra ............... SUCCESS [0.297s] [INFO] Android Extras - Apk Expansion .................... SUCCESS [0.006s] [INFO] Android Google Play APK Expansion Extra - ZIP ..... SUCCESS [0.240s] [INFO] Android Google Play APK Expansion Extra - Downloader SUCCESS [0.314s] [INFO] Android Tools ..................................... SUCCESS [0.004s] [INFO] Android Annotations ............................... SUCCESS [0.007s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5.277s [INFO] Finished at: Mon Dec 31 16:42:23 CST 2012 [INFO] Final Memory: 24M/298M [INFO] ------------------------------------------------------------------------
- 出现以上,就代表 android-maven的初步环境构建完毕
- cd ~/.m2/ 到该目录下打开repository的文件夹即可查看到已经配置好相关的Android环境了
- 测试android-maven
- 下载可供给打包测试的例子代码Download samples from the stable branch
- 解压该项目,进入jayway-maven-android-plugin-samples-b17572a 文件夹
drwxrwxr-x 4 wuyexiong wuyexiong 4096 12月 31 15:49 apidemos-android-10/ -rw-rw-r-- 1 wuyexiong wuyexiong 136 12月 19 10:25 .gitignore drwxrwxr-x 4 wuyexiong wuyexiong 4096 12月 19 10:25 helloflashlight/ drwxrwxr-x 6 wuyexiong wuyexiong 4096 12月 19 10:25 libraryprojects/ -rw-rw-r-- 1 wuyexiong wuyexiong 10173 12月 19 10:25 LICENSE.txt drwxrwxr-x 5 wuyexiong wuyexiong 4096 12月 19 10:25 morseflash/ drwxrwxr-x 13 wuyexiong wuyexiong 4096 12月 19 10:25 native/ -rw-rw-r-- 1 wuyexiong wuyexiong 7548 12月 19 10:25 pom.xml -rw-rw-r-- 1 wuyexiong wuyexiong 942 12月 19 10:25 README.txt drwxrwxr-x 4 wuyexiong wuyexiong 4096 12月 19 10:25 scala/ drwxrwxr-x 5 wuyexiong wuyexiong 4096 12月 31 15:34 support4demos/
- 可以看到都是一些例子的代码。
- 这时候可以进入具体的一个项目,比如进入support4demos
-rw-rw-r-- 1 wuyexiong wuyexiong 10630 12月 19 10:25 AndroidManifest.xml -rw-rw-r-- 1 wuyexiong wuyexiong 1909 12月 19 10:25 pom.xml -rw-rw-r-- 1 wuyexiong wuyexiong 377 12月 19 10:25 README.txt drwxrwxr-x 10 wuyexiong wuyexiong 4096 12月 19 10:25 res/ drwxrwxr-x 3 wuyexiong wuyexiong 4096 12月 19 10:25 src/
- 这是完整项目的文件了
- 打开模拟器,或者链接上手机,执行 mvn clean install 即可编该程序了
- 也可以只是执行 mvn package 来进行打包, 即可在项目下生成一个target的目录,目录底下都是一些目标文件
- 这两种默认都是以debug签名的,更多待研究了。。。
- 最后执行 mvn android:deploy 即可安装到模拟器或者手机
- 编译并安装是执行 mvn clean install android:deploy
-
[INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Android Support V4 Demos 1.0.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- android-maven-plugin:3.5.0:deploy (default-cli) @ support4demos --- [INFO] Waiting for initial device list from the Android Debug Bridge [INFO] Found 1 devices connected with the Android Debug Bridge [INFO] android.device parameter not set, using all attached devices [INFO] Successfully installed /home/wuyexiong/Android/tool/maven/jayway-maven-android-plugin-samples-b17572a/support4demos/target/support4demos.apk to MX3ACA1ALGVA8Q1125_Meizu_M031 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 8.965s [INFO] Finished at: Mon Dec 31 16:55:09 CST 2012 [INFO] Final Memory: 17M/146M [INFO] ------------------------------------------------------------------------
本章到此了,我也是刚研究这个,因为发现github上面很多开源项目都是带有pom.xml这个文件的,所以下了解一下,最好能深入一下。
循序渐进吧。等待研究更深入的东西,把笔记都记到这上面