使用了不同的Landroid/支持/v4/app/FragmentActivity;在预验证期间:Android + fragment + JUnit + Maven

时间:2022-09-04 11:50:45

I've have two Android's project built with Maven under Eclipse. One is the project itself, and the other one a test project.

我已经在Eclipse下用Maven构建了两个Android的项目。一个是项目本身,另一个是测试项目。

When I run the project as a Android JUnit Test it throws the error:

当我以Android JUnit测试的形式运行这个项目时,它会抛出错误:

java.lang.RuntimeException: Exception during suite construction
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.NoClassDefFoundError: com.some.TestClass

Looking at Logcat I've found the root cause of this error that is:

看看Logcat,我找到了这个错误的根本原因:

Lcom.some.TestClass; had used a different Landroid/support/v4/app/FragmentActivity; during pre-verification

Digging on the web I'found a similar issue with it solution was to remove the duplicated android-support-v4.jar from the test project. But this does not applies to Maven's projects due dependency inheritance.

在web上挖掘时,我发现it解决方案的一个类似问题是删除重复的android-support-v4。jar来自测试项目。但是,这并不适用于Maven的项目依赖继承。

The only way I found to get it work, was before launching I have to manually remove from the test project's build path the Maven Dependencies library and explicitly add a Project Reference to the target Android project.

我发现要让它工作的唯一方法是在启动之前,我必须从测试项目的构建路径Maven依赖库中手动删除,并显式地向目标Android项目添加项目引用。

¿Does anyone knows a way to get it work without this hack?

有谁知道一种方法可以让它在没有黑客攻击的情况下工作?

Here is a relevant fragment from my project's pom.xml:

下面是我的项目pom.xml中的一个相关片段:

<groupId>com.some</groupId>
<artifactId>project</artifactId>
<packaging>apk</packaging>
...
<dependencies>
    ...
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>support-v4</artifactId>
    </dependency>
    ...
</dependencies>

And the test project pom.xml:

测试项目pom.xml:

<groupId>com.some</groupId>
<artifactId>project-test</artifactId>
<packaging>apk</packaging>
...
<dependencies>
    ...
    <dependency>
        <groupId>com.some</groupId>
        <artifactId>project</artifactId>
        <packaging>apk</packaging>
    </dependency>

    <dependency>
        <groupId>com.some</groupId>
        <artifactId>project</artifactId>
        <packaging>jar</packaging>
    </dependency>
    ...
</dependencies>

1 个解决方案

#1


0  

Recently solved what seems to be the same problem. This is not specific to the android-support-library. Please check this answer.

最近解决了同样的问题。这不是android-support-library特有的。请检查这个答案。

#1


0  

Recently solved what seems to be the same problem. This is not specific to the android-support-library. Please check this answer.

最近解决了同样的问题。这不是android-support-library特有的。请检查这个答案。