打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
maven集成eclipse android项目办法总结

maven集成eclipse android项目办法总结  

1.安装m2eclipse-android-integration

https://svn.codespot.com/a/eclipselabs.org/m2eclipse-android-integration/updates/m2eclipse-android-integration/

其实这个不需要安,不过下面的是必须要安装的。

安装maven-android-sdk-deployer

https://github.com/mosabua/maven-android-sdk-deployer

下载完后,执行:

Java代码   
  1. cd mosabua-maven-android-sdk-deployer-df824df  
  2. mvn clean install  
  3.   
  4. #可选择安装:  
  5. mvn install -P  1.5   
  6. mvn install -P  1.6   
  7. mvn install -P  2.1   
  8. mvn install -P  2.2   
  9. mvn install -P  2.3 . 3   
  10. mvn install -P  3.0   
  11. mvn install -P  3.1   
  12. mvn install -P  3.2   
  13. mvn install -P  4.0   
  14. mvn install -P  4.0 . 3   

 如果报错,说明sdk没有安装完整(google api等等),要在android sdk manager里面下载完整,

如果运行正常的话,这一步操作就是将sdk的包放入到svn的本地仓库里了。

2.Create Eclipse project

If you already have an Android project please make sure you have created a POM for your project using version 3.0.0 or greater of the maven-android-plugin.

Then right-click on your project and select Configuration -> Convert to Maven Project.

If you are starting with a new project you can use the Maven Android archetypes to create Android projects completely within Eclipse:

Create a new Maven Project (File -> New -> Project... then select Maven -> Maven Project).

When prompted to Select Archetype click Add Archetype...

In the dialog that appears enter "de.akquinet.android.archetypes" for Archetype Group Id.

In Archetype Artifact Id enter "android-quickstart".

In Archetype Version enter "1.0.8" and continue.

When prompted enter your desired project group and artifact ID, version and, optionally, set the "platform" property for the Android version (defaults to '10').

Click Finish

Right-click on new project and select Maven -> Update Project Configuration.

3.Install Android Connector

Windows->Preferences->Maven->Discovery->Open Catalog->安装m2e connector for android

4.至此新建的项目应该不会再报错了。

5.配置maven插件,自动打包签名,附上我的完整的pom:

Xml代码   
  1. < project   xmlns = "http://maven.apache.org/POM/4.0.0"   xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"   
  2.           xsi:schemaLocation ="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" >  
  3.      < modelVersion > 4.0.0 </ modelVersion >   
  4.      < groupId > com.olivephone </ groupId >   
  5.      < artifactId > olive-browser </ artifactId >   
  6.      < version > 1.0.10 </ version >   
  7.      < packaging > apk </ packaging >   
  8.      < name > olive-browser </ name >   
  9.       
  10.      < properties >   
  11.          < platform.version > 2.2.1 </ platform.version >   
  12.      </ properties >   
  13.       
  14.      < dependencies >   
  15.          < dependency >   
  16.              < groupId > com.google.android </ groupId >   
  17.              < artifactId > android </ artifactId >   
  18.              < version > ${platform.version} </ version >   
  19.              < scope > provided </ scope >   
  20.          </ dependency >   
  21.          < dependency >   
  22.              < groupId > com.google.android </ groupId >   
  23.              < artifactId > support-v4 </ artifactId >   
  24.              < version > r7 </ version >   
  25.          </ dependency >   
  26.          < dependency >   
  27.              < groupId > commons-io </ groupId >   
  28.              < artifactId > commons-io </ artifactId >   
  29.              < version > 2.0.1 </ version >   
  30.          </ dependency >   
  31.          < dependency >   
  32.              < groupId > org.apache.commons </ groupId >   
  33.              < artifactId > commons-lang3 </ artifactId >   
  34.              < version > 3.1 </ version >   
  35.          </ dependency >   
  36.          < dependency >   
  37.              < groupId > org.jsoup </ groupId >   
  38.              < artifactId > jsoup </ artifactId >   
  39.              < version > 1.6.1 </ version >   
  40.          </ dependency >   
  41.          < dependency >   
  42.              < groupId > com.google.android </ groupId >   
  43.              < artifactId > libGoogleAnalytics </ artifactId >   
  44.              < version > 1.0 </ version >   
  45.          </ dependency >   
  46.      </ dependencies >   
  47.           
  48.      < build >   
  49.          < plugins >   
  50.              < plugin >   
  51.                  < groupId > com.jayway.maven.plugins.android.generation2 </ groupId >   
  52.                  < artifactId > android-maven-plugin </ artifactId >   
  53.                  < version > 3.1.1 </ version >   
  54.                  < configuration >   
  55.                      < androidManifestFile > ${project.basedir}/AndroidManifest.xml </androidManifestFile >   
  56.                      < assetsDirectory > ${project.basedir}/assets </ assetsDirectory >   
  57.                      < resourceDirectory > ${project.basedir}/res </ resourceDirectory >   
  58.                      < nativeLibrariesDirectory > ${project.basedir}/src/main/native </nativeLibrariesDirectory >   
  59.                      < sdk >   
  60.                          < platform > 8 </ platform >   
  61.                      </ sdk >   
  62.                      < undeployBeforeDeploy > true </ undeployBeforeDeploy >   
  63.                  </ configuration >   
  64.                  < extensions > true </ extensions >   
  65.              </ plugin >   
  66.   
  67.              < plugin >   
  68.                  < artifactId > maven-compiler-plugin </ artifactId >   
  69.                  < version > 2.3.2 </ version >   
  70.                  < configuration >   
  71.                      < source > 1.6 </ source >   
  72.                      < target > 1.6 </ target >   
  73.                      < encoding > UTF8 </ encoding >   
  74.                  </ configuration >   
  75.              </ plugin >   
  76.               
  77.              < plugin >   
  78.                  < groupId > org.apache.maven.plugins </ groupId >   
  79.                  < artifactId > maven-jarsigner-plugin </ artifactId >   
  80.                  < version > 1.2 </ version >   
  81.                  < executions >   
  82.                    < execution >   
  83.                      < id > sign </ id >   
  84.                      < goals >   
  85.                        < goal > sign </ goal >   
  86.                      </ goals >   
  87.                    </ execution >   
  88.                    < execution >   
  89.                      < id > verify </ id >   
  90.                      < goals >   
  91.                        < goal > verify </ goal >   
  92.                      </ goals >   
  93.                    </ execution >   
  94.                  </ executions >   
  95.                  < configuration >   
  96.                      < encoding > UTF-8 </ encoding >   
  97.                      < includes >   
  98.                              < include > target/${artifactId}.apk </ include >   
  99.                              </ includes >      
  100.                              < removeExistingSignatures > true </ removeExistingSignatures >   
  101.                              < keystore > ${keyFilePath} </ keystore >   
  102.                      < storepass > ${storePassword} </ storepass >   
  103.                      < keypass > ${keyPassword} </ keypass >   
  104.                      < alias > ${keyAlias} </ alias >   
  105.                  </ configuration >   
  106.              </ plugin >   
  107.                 
  108.          < plugin >   
  109.                   < groupId > org.codehaus.mojo </ groupId >   
  110.                   < artifactId > exec-maven-plugin </ artifactId >   
  111.                   < version > 1.2.1 </ version >   
  112.                   < executions >   
  113.                       < execution >   
  114.                           < id > zipalign </ id >   
  115.                           < goals >   
  116.                               < goal > exec </ goal >   
  117.                           </ goals >   
  118.                           < phase > install </ phase >   
  119.                           < configuration >   
  120.                               < executable > ${ANDROID_HOME}/tools/zipalign </ executable >  
  121.                                < arguments >   
  122.                                   < argument > -f </ argument >   
  123.                                   < argument > 4 </ argument >   
  124.                                   < argument > target/${project.build.finalName}.apk </ argument >  
  125.                                   < argument > target/${project.build.finalName}-zipped.apk </argument >   
  126.                               </ arguments >   
  127.                           </ configuration >   
  128.                       </ execution >   
  129.                   </ executions >   
  130.          </ plugin >   
  131.          </ plugins >    
  132.      </ build >   
  133.       
  134. </ project >   
 

setting.xml

Xml代码   
  1. < settings   xmlns = "http://maven.apache.org/POM/4.0.0"   
  2. xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"   
  3. xsi:schemaLocation ="http://maven.apache.org/POM/4.0.0  
  4.                                http://maven.apache.org/xsd/settings-1.0.0.xsd" >   
  5.   
  6. <!-- add by peirenlei here one line-->   
  7. < localRepository > D:/3rdlib/java/m2/repository </ localRepository >   
  8.   
  9. < profiles >   
  10.      < profile >   
  11.          < id > sign </ id >   
  12.          < activation >   
  13.              < activeByDefault > true </ activeByDefault >   
  14.          </ activation >   
  15.          < properties >   
  16.              < keyFilePath > E:/MyDocument/xxxx.keystore </ keyFilePath >   
  17.              < storePassword > 就不告诉你 </ storePassword >   
  18.              < keyPassword > 就不告诉你 </ keyPassword >   
  19.              < keyAlias > 就不告诉你 </ keyAlias >   
  20.          </ properties >   
  21.      </ profile >   
  22.   
  23. </ profiles >   
  24. < activeProfiles >   
  25.     < activeProfile > sign </ activeProfile >   
  26. </ activeProfiles >   
  27.   
  28. </ settings >   
 

特别提醒:

1.<removeExistingSignatures>true</removeExistingSignatures>这个一定要配上,我之前参考网上的都没有这一项,结果就是签名的apk里面有两个签名,一个是自己的一个是android debug的,so...

2.记住源代码的路径要更改为:src/main/java,否则在package的时候会抱错,并且就算不抱错,打好的包在真机上也运行不了,谨记,为这个事情,我折磨了一整天。

6.配置这这一切,接下来就是爽歪歪的时候了: 

Java代码   
  1. mvn clean  package   

 进入target目录,看到的mvndemo-1.0.9.apk就是已经签过名的apk,怎么?不相信,自己看看:

Java代码   
  1. jarsigner -verify -verbose -certs "F:\workspace\android_workspace\mvndemo\target\mvndemo-1.0.9.apk"   
 

看到没?打印出来的信息里,是不是有自己的签名信息。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
maven常用命令介绍
maven2 (二) SCM
maven 简单实用教程 - Open source of memory - JavaEy...
Maven下,spring+struts2+ibatis整合
Maven使用常见问题
maven常用命令
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服