【发布时间】:2011-04-30 05:24:51
【问题描述】:
我想为 Android 启动一个项目,但我真的很喜欢使用 Maven 构建它。 Google 是否为 Maven 提供支持或计划支持它?如果有人至少知道我可以同时使用的 Maven 原型,那就太好了。提前致谢。
【问题讨论】:
我想为 Android 启动一个项目,但我真的很喜欢使用 Maven 构建它。 Google 是否为 Maven 提供支持或计划支持它?如果有人至少知道我可以同时使用的 Maven 原型,那就太好了。提前致谢。
【问题讨论】:
好像有a maven plugin for that :-)
【讨论】:
我真正想要的是an article like this,但我在回答完问题后找到了它。
更新: SpringSource 的人做了一个 Spring Android 项目,支持在 Android 环境中使用 Spring Framework 和have Maven support。我会试试看的。
这是一篇关于 Spring Android 和 Maven 使用 Eclipse 3.6 和 Android SDK 9 的文章,分为两部分:
【讨论】:
The Android Maven plugin 已更新以支持在 Android SDK r14 版本中所做的更改。您将需要调整您的 POM 以使用新版本。我在构建我的应用程序时遇到了新版本的内存不足错误,因此请注意 dex jvmArguments 部分以允许更多可用内存。
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.0.0-alpha-13</version>
<configuration>
<sdk>
<platform>${android-platform}</platform>
</sdk>
<dex>
<jvmArguments>
<jvmArgument>-Xms256m</jvmArgument>
<jvmArgument>-Xmx512m</jvmArgument>
</jvmArguments>
</dex>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
最新版本的 Eclipse 的 Android Configurator (m2e-android) 也支持 r14 中的更改。最后,我在 SpringSource 网站上发布了一个名为 Updated Maven Support for Android Projects 的后续博客,其中介绍了这些工具的更新。
【讨论】:
这是我为 Eclipse 中的现有 android 项目添加 maven 支持所做的工作。我通过 Eclipse 市场安装了“m2e”插件。然后我安装了“m2e-android”插件。目前它在 Eclipse 市场中被称为“Android Configurator for M2E”。安装完这两个插件并重启Eclipse后,右键一个已有的android项目-->Configure-->Convert to Maven Project。为您的项目选择一个唯一的组 ID 和工件 ID,然后单击完成。将以下内容复制到项目的 pom.xml 中,并替换现有的所有内容。将 'dependencies' 下的 'version' 标签的值更改为您正在使用的 SDK 版本。还将文件末尾附近的“平台”标签的值更改为您的平台值。不要忘记更改 xml 的 groupId、artifactId 和名称。
<?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>org.myproject</groupId>
<artifactId>MyProject</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>MyProject</name>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.3.3</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.3.0</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>10</platform>
</sdk>
</configuration>
</plugin>
</plugins>
</build>
</project>
之后右键单击项目-->Maven-->更新项目。如果 Eclipse 抱怨 xml 中的错误,您可能需要安装 maven 然后运行
mvn clean install
从包含 pom.xml 文件的文件夹中的控制台。
【讨论】:
正如@Riduidel 之前所说,您可以使用 com.jayway.maven.plugins.android.generation2 插件。
注意,您不需要下载任何插件,您只需拥有使用此插件的 maven。
我是怎么做到的:
手动将 pom.xml 添加到您的 android 项目(到项目的根目录)。
下载 apache-maven-3.1.1 并将您的 bin 文件夹(例如 D:\java\apache-maven-3.1.1\bin;)添加到环境变量中的路径。
在 [Your_maven_path]\conf 中使用下一个配置 settings.xml:
<pluginGroups>
<pluginGroup>com.jayway.maven.plugins.android.generation2</pluginGroup>
</pluginGroups>
将内容添加到 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.example.ENumbers</groupId>
<artifactId>ENumbers</artifactId>
<version>1.0</version>
<packaging>apk</packaging>
<name>MainApp</name>
<properties>
<platform.version>2.2.1</platform.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.7.1</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>xpp3</artifactId>
<groupId>xpp3</groupId>
</exclusion>
<exclusion>
<artifactId>stax-api</artifactId>
<groupId>stax</groupId>
</exclusion>
<exclusion>
<artifactId>stax</artifactId>
<groupId>stax</groupId>
</exclusion>
<exclusion>
<artifactId>spring-web</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
<resourceDirectory>${project.basedir}/res</resourceDirectory>
<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
<sdk>
<path>
D:\Program Files\Android\android-sdk
</path>
<platform>22</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
查看重要的 <packaging>, <build> 节点,它的内容和 com.google.android 依赖项。
【讨论】: