5

我正在尝试将 powermock-mockito 和 mockito 添加到 Android 测试项目中。我使用 android 命令行工具创建了 android 测试项目来创建 build.xml 和项目结构。我的 libs/ 目录中有以下 jars:

  • dexmaker-1.0.jar
  • dexmaker-mockito-1.0.jar
  • mockito-all-1.9.5.jar
  • powermock-mockito-1.5-full.jar

当我尝试使用 ant debug 构建项目时,出现以下错误:

[apkbuilder] Creating ProjectTests-debug-unaligned.apk and signing it with a debug key...
[apkbuilder] Found duplicate file for APK: mockito-extensions/org.mockito.plugins.MockMaker
[apkbuilder] Origin 1: /home/cmiller/Projects/android-project/ProjectTests/libs/powermock-mockito-1.5-full.jar
[apkbuilder] Origin 2: /home/cmiller/Projects/android-project/ProjectTests/libs/powermock-mockito-1.5-full.jar

BUILD FAILED
/home/cmiller/Applications/adt-bundle-linux/sdk/tools/ant/build.xml:951: The following error occurred while executing this line:
/home/cmiller/Applications/adt-bundle-linux/sdk/tools/ant/build.xml:962: The following error occurred while executing this line:
/home/cmiller/Applications/adt-bundle-linux/sdk/tools/ant/build.xml:319: com.android.sdklib.build.DuplicateFileException: Duplicate files at the same path inside the APK

我不确定它是如何在单个 jar 中找到重复文件的。build.xml 文件根本没有被修改,我还没有创建 custom_rules.xml。任何帮助将不胜感激。

4

2 回答 2

3

Just remove the duplicate class org.mockito.plugins.MockMaker from one of the jars. I solved this by doing the following:

  1. Make backup copy of powermock-mockito-1.5-full.jar
  2. Rename powermock-mockito-1.5-full.jar to powermock-mockito-1.5-full.zip
  3. Unzip powermock-mockito-1.5-full.zip
  4. rm -rf mockito-extensions
  5. jar cf powermock-mockito-1.5-full.jar META-INF/ org/
  6. Put the updated jar in the libs folder.
于 2013-08-29T18:49:01.787 回答
2

您是否检查过该文件是否真的在 jar 文件中重复?Afaik 可以在一个 zip 文件中包含两次相同的文件。在该文件中从 jar 中删除它可能会有所帮助。不知道它会如何到达那里。

于 2013-04-21T05:55:06.837 回答