一、下载安装 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
安装:
cd maven-android-sdk-deployer-master mvn clean install
或 - 指定版本
cd maven-android-sdk-deployer-master mvn clean install -P 4.2
七、新建Android工程:HelloAndy
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloandy"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.helloandy.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
project.properties
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-17
八、转换成Maven工程
项目 --> 右键 --> Configure --> Convert to Maven Project
九、修改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>HelloAndy</groupId>
<artifactId>HelloAndy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>apk</packaging>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>${project.artifactId}</finalName>
<!-- <sourceDirectory>src</sourceDirectory> -->
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.6.0</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>
com.jayway.maven.plugins.android.generation2
</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
<resourceDirectory>${project.basedir}/res</resourceDirectory>
<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
<run>
<debug>true</debug>
</run>
<sdk>
<platform>17</platform>
</sdk>
<emulator>
<avd>16</avd>
</emulator>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>${project.build.sourceEncoding}</encoding>
<optimize>true</optimize>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
</project>
十、打包测试
>mvn clean install android:apk
待续....

本文详细介绍如何从零开始搭建一个基于Maven的Android项目,包括安装ADT Bundle、配置环境变量、使用Eclipse Marketplace安装插件、创建Android工程、转换为Maven项目、配置pom.xml文件及最终的打包测试。
6832

被折叠的 条评论
为什么被折叠?



