Maven搭建Android开发环境

来源:互联网 发布:森松尼鼠标怎么样 知乎 编辑:程序博客网 时间:2024/05/17 12:24

转载于:http://feticoolo.iteye.com/blog/1910033

一、下载安装 ADT Bundle

        下载:http://developer.android.com/sdk/index.html

        安装:解压即可

 

二、安装插件:Eclipse Marketplace

 

三、安装插件:Android Configurator for M2E

 

四、设置环境变量:ANDROID_HOME

        例如:ANDROID_HOME=D:\Java\adt-bundle-windows-x86_64-20130522\sdk

 

五、设置环境变量:PATH

        将 %ANDROID_HOME%\tools; 与 %ANDROID_HOME%\platform-tools; 添加到PATH下

        例如:PATH=%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;

 

六、下载安装:maven-android-sdk-deployer

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

        安装:

Cmd代码  收藏代码
  1. cd maven-android-sdk-deployer-master  
  2. mvn clean install  

        或 - 指定版本

Cmd代码  收藏代码
  1. cd maven-android-sdk-deployer-master  
  2. mvn clean install -P 4.2  

 

七、新建Android工程:HelloAndy

    AndroidManifest.xml

Xml代码  收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="com.example.helloandy"  
  4.     android:versionCode="1"  
  5.     android:versionName="1.0" >  
  6.   
  7.     <uses-sdk  
  8.         android:minSdkVersion="10"  
  9.         android:targetSdkVersion="10" />  
  10.   
  11.     <application  
  12.         android:allowBackup="true"  
  13.         android:icon="@drawable/ic_launcher"  
  14.         android:label="@string/app_name"  
  15.         android:theme="@style/AppTheme" >  
  16.         <activity  
  17.             android:name="com.example.helloandy.MainActivity"  
  18.             android:label="@string/app_name" >  
  19.             <intent-filter>  
  20.                 <action android:name="android.intent.action.MAIN" />  
  21.   
  22.                 <category android:name="android.intent.category.LAUNCHER" />  
  23.             </intent-filter>  
  24.         </activity>  
  25.     </application>  
  26.   
  27. </manifest>  

 

    project.properties

Properties代码  收藏代码
  1. # This file is automatically generated by Android Tools.  
  2. # Do not modify this file -- YOUR CHANGES WILL BE ERASED!  
  3. #  
  4. # This file must be checked in Version Control Systems.  
  5. #  
  6. # To customize properties used by the Ant build system edit  
  7. "ant.properties", and override values to adapt the script to your  
  8. # project structure.  
  9. #  
  10. # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):  
  11. #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt  
  12.   
  13. # Project target.  
  14. target=android-17  

  

八、转换成Maven工程

       项目 --> 右键 --> Configure --> Convert to Maven Project

 

九、修改pom.xml配置

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/xsd/maven-4.0.0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.     <groupId>HelloAndy</groupId>  
  5.     <artifactId>HelloAndy</artifactId>  
  6.     <version>0.0.1-SNAPSHOT</version>  
  7.     <packaging>apk</packaging>  
  8.     <dependencies>  
  9.         <dependency>  
  10.             <groupId>com.google.android</groupId>  
  11.             <artifactId>android</artifactId>  
  12.             <version>2.3.3</version>  
  13.             <scope>provided</scope>  
  14.         </dependency>  
  15.     </dependencies>  
  16.     <properties>  
  17.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  18.     </properties>  
  19.     <build>  
  20.         <finalName>${project.artifactId}</finalName>  
  21.         <!-- <sourceDirectory>src</sourceDirectory> -->  
  22.         <pluginManagement>  
  23.             <plugins>  
  24.                 <plugin>  
  25.                     <groupId>com.jayway.maven.plugins.android.generation2</groupId>  
  26.                     <artifactId>android-maven-plugin</artifactId>  
  27.                     <version>3.6.0</version>  
  28.                     <extensions>true</extensions>  
  29.                 </plugin>  
  30.             </plugins>  
  31.         </pluginManagement>  
  32.         <plugins>  
  33.             <plugin>  
  34.                 <groupId>  
  35.                     com.jayway.maven.plugins.android.generation2  
  36.                 </groupId>  
  37.                 <artifactId>android-maven-plugin</artifactId>  
  38.                 <configuration>  
  39.                     <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>  
  40.                     <assetsDirectory>${project.basedir}/assets</assetsDirectory>  
  41.                     <resourceDirectory>${project.basedir}/res</resourceDirectory>  
  42.                     <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>  
  43.                     <run>  
  44.                         <debug>true</debug>  
  45.                     </run>  
  46.                     <sdk>  
  47.                         <platform>17</platform>  
  48.                     </sdk>  
  49.                     <emulator>  
  50.                         <avd>16</avd>  
  51.                     </emulator>  
  52.                     <deleteConflictingFiles>true</deleteConflictingFiles>  
  53.                     <undeployBeforeDeploy>true</undeployBeforeDeploy>  
  54.                 </configuration>  
  55.             </plugin>  
  56.             <plugin>  
  57.                 <groupId>org.apache.maven.plugins</groupId>  
  58.                 <artifactId>maven-compiler-plugin</artifactId>  
  59.                 <version>3.1</version>  
  60.                 <configuration>  
  61.                     <source>1.6</source>  
  62.                     <target>1.6</target>  
  63.                     <encoding>${project.build.sourceEncoding}</encoding>  
  64.                     <optimize>true</optimize>  
  65.                     <showWarnings>true</showWarnings>  
  66.                     <showDeprecation>true</showDeprecation>  
  67.                 </configuration>  
  68.             </plugin>  
  69.         </plugins>  
  70.     </build>  
  71. </project>  

  

十、打包测试

Cmd代码  收藏代码
  1. >mvn clean install android:apk  

 

原创粉丝点击