Maven搭建Android开发环境

 

一、下载安装 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

 

 

待续.... 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值