【发布时间】:2014-11-21 04:54:18
【问题描述】:
我是 Maven 的新手,我试图在我的 Android 项目中使用它。
我有 ADT,并且我已经为 Eclipse 安装了 m2e 插件。
通过右键单击,我已将项目转换为 Maven 项目,并且我已将(几乎)所有 jar 库文件替换为 Maven。
现在我正在尝试运行我的项目,该项目使用自定义库项目(也使用 Maven),但每次更改 pom 时都会出现新错误。
这是我图书馆的 pom:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.group.id</groupId>
<artifactId>com.my.artifact.id</artifactId>
<version>0.1</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>4.0.0-rc.1</version>
<configuration>
<sdk>
<path>${env.ANDROID_HOME}</path>
<platform>10</platform>
</sdk>
<deleteConflictingFiles>true</deleteConflictingFiles>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</build>
<dependencies>
[All my dependencies in Maven]
</dependencies>
这是我项目的 pom 文件:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.project.groupid</groupId>
<artifactId>com.my.project.artifactid</artifactId>
<version>0.4</version>
<packaging>apk</packaging>
<dependencies>
<dependency>
<groupId>com.my.group.id</groupId>
<artifactId>com.my.artifact.id</artifactId>
<version>0.1</version>
</dependency>
[All other dependencies]
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>4.0.0-rc.1</version>
<configuration>
<sdk>
<path>${env.ANDROID_HOME}</path>
<platform>10</platform>
</sdk>
<deleteConflictingFiles>true</deleteConflictingFiles>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</build>
现在,使用此配置,当我尝试启动应用程序时出现此错误:
[2014-09-26 09:45:44 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/xmlpull/v1/XmlPullParser;
[2014-09-26 09:45:44 - MyProjectName] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/xmlpull/v1/XmlPullParser;
这是我的一个依赖项使用的库。 在这两个项目中,在 Properties --> Build Path --> Order 和 Export 我只检查了 Maven 依赖项。
但是,如果我尝试在两个项目中取消选中此选项,我可以运行应用程序,但是当我尝试实例化我的库项目的一个类时,应用程序会因以下错误而崩溃:
09-26 10:08:16.318: E/AndroidRuntime(2023): FATAL EXCEPTION: main
09-26 10:08:16.318: E/AndroidRuntime(2023): Process: com.example.myapp, PID: 2023
09-26 10:08:16.318: E/AndroidRuntime(2023): java.lang.NoClassDefFoundError: com.example.myapp.MyExampleClassTask
在部署和启动时,我的应用程序 logcat 将其打印在:
09-26 10:05:44.318: W/dalvikvm(2023): Unable to resolve superclass of Lcom/example/myapp/MyExampleClassTask; (30)
09-26 10:05:44.318: W/dalvikvm(2023): Link of class 'Lcom/example/myapp/MyExampleClassTask;' failed
09-26 10:05:44.318: E/dalvikvm(2023): Could not find class 'com.example.myapp.MyExampleClassTask', referenced from method com.example.myapp.MainFragment$1.onClick
09-26 10:05:44.318: W/dalvikvm(2023): VFY: unable to resolve new-instance 68 (Lcom/example/myapp/MyExampleClassTask;) in Lcom/example/myapp/MainFragment$1;
MyExampleClassTask 是一个扩展了我的库类的类。
我希望有人可以帮助我。谢谢=)
【问题讨论】:
标签: android eclipse maven adt m2eclipse