利用android-maven-plugin,
前提要求:
1,maven 3.0.3以上,
2,配置 settings.xml
settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <profiles> <profile> <id>android</id> <properties> <android.sdk.path> [path to android home] </android.sdk.path> </properties> </profile> </profiles> <activeProfiles> <!--make the profile active all the time --> <activeProfile>android</activeProfile> </activeProfiles> </settings>
范例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.simpligility.android</groupId> <artifactId>helloflashlight</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>apk</packaging> <name>HelloFlashlight</name> <dependencies> <dependency> <groupId>com.google.android</groupId> <artifactId>android</artifactId> <version>1.6_r2</version> <scope>provided</scope> </dependency> </dependencies> <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.5.3</version> <extensions>true</extensions> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <configuration> <sdk> <!-- platform or api level (api level 4 = platform 1.6)--> <platform>4</platform> </sdk> </configuration> </plugin> </plugins> </build> </project>