简体   繁体   English

maven对android项目的支持?

[英]maven support for android projects?

I want to start a project for Android but i really like to build it using Maven. 我想开始一个Android项目,但我真的很想用Maven构建它。 Does Google provide support for Maven or plan to support it? Google是否为Maven提供支持或计划支持它? It would be great if anybody know at least an archetype for Maven that I can use meanwhile. 如果有人知道至少我可以同时使用Maven的原型,那将是很棒的。 Thanks in advance. 提前致谢。

好像有一个maven插件 :-)

What I really wanted was an article like this , but i found it after the question was answered. 我真正想要的是这样的文章 ,但我在问题得到解答后找到了。

Update: People at SpringSource did a Spring Android project that supports the usage of the Spring Framework in an Android environment and have Maven support . 更新: SpringSource的人员做了一个Spring Android项目,该项目支持在Android环境中使用Spring Framework并支持Maven I will give it a try. 我会试试看。

Here is an article about Spring Android and Maven using Eclipse 3.6 and Android SDK 9, split in two parts: 这是一篇关于使用Eclipse 3.6和Android SDK 9的Spring Android和Maven的文章,分为两部分:

First part 第一部分

Second part 第二部分

The Android Maven plugin has been updated to support changes made in the Android SDK r14 release. Android Maven插件已更新,以支持Android SDK r14版本中所做的更改。 You will need to adjust your POM to use the new version. 您需要调整POM才能使用新版本。 I experienced an out of memory error with the new version when building my app, so note the dex jvmArguments section to allow for more available memory. 在构建我的应用程序时,我遇到了新版本的内存不足错误,因此请注意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>

The latest version of the Android Configurator (m2e-android) for Eclipse also supports the changes in r14. Eclipse的Android Configurator(m2e-android)的最新版本也支持r14中的更改。 Lastly, I've posted a follow up blog on the SpringSource site called Updated Maven Support for Android Projects , which goes over these updates to the tools. 最后,我在SpringSource网站上发布了一个名为Updated Maven Support for Android Projects的后续博客,该博客将对这些工具进行更新。

Here is what I did to add maven support to an existing android project in Eclipse. 这是我在Eclipse中为现有的android项目添加maven支持所做的。 I installed the 'm2e' plugin via the Eclipse market place. 我通过Eclipse市场安装了'm2e'插件。 Then I installed the 'm2e-android' plugin. 然后我安装了'm2e-android'插件。 At the moment it is called 'Android Configurator for M2E' in Eclipse market place. 目前它在Eclipse市场上被称为“M2 Conficerator for M2E”。 After installing the two plugins and restarting Eclipse, right click on an existing android project-->Configure-->Convert to Maven Project. 安装完两个插件并重新启动Eclipse后,右键单击现有的android项目 - > Configure - > Convert to Maven Project。 Choose a unique group id and an artifact id for your project then click finish. 为项目选择唯一的组ID和工件ID,然后单击“完成”。 Copy the following contents to the pom.xml of the project and replace all the existing contents. 将以下内容复制到项目的pom.xml并替换所有现有内容。 Change the value of the 'version' tag under 'dependencies' to the SDK version you are using. 将“依赖项”下的“版本”标记的值更改为您正在使用的SDK版本。 Also change the value of the 'platform' tag near the end of the file to the value of your platform. 还要将文件末尾附近的“platform”标记的值更改为平台的值。 Do not forget to also change the groupId, artifactId and name of the xml. 别忘了还要更改groupId,artifactId和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>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>

After that right click on the project-->Maven-->Update Project. 然后右键单击项目 - > Maven - > Update Project。 If Eclipse is complaining about errors in the xml, you may want to install maven then run 如果Eclipse抱怨xml中的错误,您可能需要安装maven然后运行

mvn clean install

from the console in the folder that contains the pom.xml file. 从包含pom.xml文件的文件夹中的控制台。

as @Riduidel said before, you can use com.jayway.maven.plugins.android.generation2 plugin. 正如@Riduidel之前所说,你可以使用com.jayway.maven.plugins.android.generation2插件。
Note , that you don't need download any plugins, you need to have just the maven for using this plugin. 请注意 ,您不需要下载任何插件,您只需要使用此插件的maven。
How I did it: 我是怎么做到的

  1. manually add pom.xml to your android project (to the root of project). 手动将pom.xml添加到您的android项目(到项目的根目录)。

  2. download apache-maven-3.1.1 and add your bin folder ( ex D:\\java\\apache-maven-3.1.1\\bin;) to path in Environment Variables. 下载apache-maven-3.1.1并将您的bin文件夹(例如D:\\ java \\ apache-maven-3.1.1 \\ bin;)添加到Environment Variables中的路径。

  3. configure settings.xml in [Your_maven_path]\\conf with next: 使用下一步在[Your_maven_path] \\ conf中配置settings.xml

     <pluginGroups> <pluginGroup>com.jayway.maven.plugins.android.generation2</pluginGroup> </pluginGroups> 
  4. Add content to pom.xml . 将内容添加到pom.xml My example: 我的例子:

      <?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> 

Look at important <packaging>, <build> nodes, it's content and com.google.android dependency. 查看重要的<packaging>, <build>节点,它的内容和com.google.android依赖项。

  1. Now you can open Maven window in your IDE. 现在,您可以在IDE中打开Maven窗口。 For Intellij Idea I do it next: 对于Intellij Idea,我接下来会这样做:
    Edit->Tool Windows->Maven and add your pom.xm l for initializing maven directory. 编辑 - >工具Windows-> Maven并添加你的pom.xm l来初始化maven目录。
  2. That's all. 就这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM