如何在 maven 和 eclipse 中使用 android 库 (apklibs)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11190932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I use android libraries (apklibs) with maven and eclipse?
提问by mogoh
I am using Eclipse 3.7.2 + Android + Maven + m2e and I have a problem with Android libraries included via Maven as apklibs. I built a test scenario with two projects, mvntest1(the main project) and mvntest2(my library project). The pom.xml
's are included after this text.
我正在使用 Eclipse 3.7.2 + Android + Maven + m2e,我遇到了通过 Maven 作为 apklibs 包含的 Android 库的问题。我用两个项目构建了一个测试场景,mvntest1(主项目)和mvntest2(我的库项目)。的pom.xml
包含在此文本之后。
So far so good. I can build mvntest2via console $ mvn install
without any errors. Thus, I have an apklib in my local maven repository (~/.m2/repository/mvntest2/mvntest2/0.0.1-SNAPSHOT/mvntest2-0.0.1-SNAPSHOT.apklib
).
到现在为止还挺好。我可以通过控制台构建mvntest2$ mvn install
没有任何错误。因此,我在本地 Maven 存储库 ( ~/.m2/repository/mvntest2/mvntest2/0.0.1-SNAPSHOT/mvntest2-0.0.1-SNAPSHOT.apklib
) 中有一个 apklib 。
But: The including does not work. Eclipse does not include the classes, etc. of mvntest2in mvntest1. I have cleaned, updated the configuration and dependencies and nothing help.
但是:包括不起作用。Eclipse在mvntest1中不包含mvntest2的类等。我已经清理、更新了配置和依赖项,但没有任何帮助。
What am I doing wrong? Please help. If some informations are missing, just ask.
我究竟做错了什么?请帮忙。如果缺少某些信息,请询问。
======= mvntest1/pom.xml =====
====== mvntest1/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>mvntest1</groupId>
<artifactId>mvntest1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>apk</packaging>
<name>mvntest1</name>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mvntest2</groupId>
<artifactId>mvntest2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>apklib</type>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.0.0</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>
<platform>7</platform>
</sdk>
<deleteConflictingFiles>true</deleteConflictingFiles>
<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>
====== mvntest2/pom.xml =====
====== mvntest2/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>mvntest2</groupId>
<artifactId>mvntest2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>apklib</packaging>
<name>mvntest2</name>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.1.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.0.0</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>
<platform>7</platform>
</sdk>
<deleteConflictingFiles>true</deleteConflictingFiles>
<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>
回答by Ricardo Gladwell
Support for apklib dependencies in ADT Eclipse is part of ongoing work for the m2e-androidproject and is not yet complete. Please comment on this issue to stay updated:
在 ADT Eclipse 中支持 apklib 依赖项是 m2e -android项目正在进行的工作的一部分,但尚未完成。请对此问题发表评论以保持更新:
https://github.com/rgladwell/m2e-android/issues/8
https://github.com/rgladwell/m2e-android/issues/8
UPDATE 26th September 2013:Android Connector for Maven Eclipse (m2e-android) version 0.4.3 now has been released with full support for Android Libraries.
2013 年 9 月 26 日更新:适用于 Maven Eclipse (m2e-android) 版本 0.4.3 的 Android 连接器现已发布,完全支持 Android 库。