|
Maven
一个项目管理工具,类似于Ant。相比Ant,Maven更强大,编写起来更简洁,并引入了仓库的概念。
官网:http://maven.apache.org/
配置构建环境
1.安装Android SDK
到http://developer.android.com/sdk/index.html
下载并SDK Management.
下载需要的android平台版本,和对应版本的Google api.
在系统环境变量中添加ANDROID_HOME变量,指向SDK根目录。还可以在Path中添加%ANDROID_HOME%\tools。
2.安装Maven Android SDK deployer工具
到http://github.com/mosabua/maven-android-sdk-deployer
下载项目源码,解压到任意目录下。
定位到项目目录,执行以下命令:
// 如果你的SDK下载了完整的组件
mvn clean install
// 如果你想指定某个平台
mvn clean install -P 2.2
3.配置settings.xml
为了能在命令行中使用简短的插件名-android,你需要修改settings.xml如下:
<pluginGroups>
<pluginGroup>
com.jayway.maven.plugins.android.generation2
</pluginGroup>
</pluginGroups>
在Android开发中使用Maven
在原有的Android目录下添加pom.xml文件,文件内容格式如下:
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo.quartzclock</groupId>
<artifactId>quartzclock</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>QuartzClockDemo</name>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>sonatype</id>
<name>Sonatype Repository</name>
<url>https://repository.sonatype.org/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<layout>default</layout>
</repository>
</repositories>
<build>
<finalName>${project.artifactId}</finalName>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>maven-android-plugin</artifactId>
<version>2.8.4</version>
<configuration>
<sdk>
<!-- platform or api level (api level 4 = platform 1.6)-->
<platform>8</platform>
</sdk>
<emulator>
<!-- the name of the avd device to use for starting the emulator -->
<avd>android2.2_HVGA</avd>
</emulator>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<!-- version 2.3 defaults to java 1.5, so no further configuration needed-->
<version>2.3</version>
</plugin>
</plugins>
</build>
</project>
Eclipse插件:Maven Android Plugin
请参考:
m2eclipse-android-integration
[url=]GettingStarted:http://code.google.com/a/eclipse ... wiki/GettingStarted[/url]
maven-android-plugin
[url=]GettingStarted:http://code.google.com/p/maven-android-plugin/wiki/GettingStarted[/url]
------------------------------------------------------------------------------------------------------
由于本身Android的Manifest.xml已经配置了构建的属性,感觉Maven在这起的作用不大... |
|