Apkbuilder在添加powermock到android测试项目时发现重复的文件



我试图将powermock-mockito和mockito添加到Android测试项目中。我使用android命令行工具创建了android测试项目,并创建了build.xml和项目结构。在我的lib/目录中有以下jar文件:

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

当我尝试用ant调试构建项目时,我得到以下错误:

[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。

只需从其中一个jar中删除重复的org.mockito.plugins.MockMaker类。我通过以下方法解决了这个问题:

  1. 备份powermock-mockito-1.5-full.jar
  2. powermock-mockito-1.5-full.jar重命名为powermock-mockito-1.5-full.zip
  3. 解压缩powermock-mockito-1.5-full.zip
  4. rm -rf mockito-extensions
  5. jar cf powermock-mockito-1.5-full.jar META-INF/ org/
  6. 将更新后的jar放到libs文件夹中。

您是否检查过该文件是否真的在jar文件中重复?在一个zip文件中可能有两个相同的文件。在那个文件中,将它从jar中移除可能会有所帮助。我不知道它是怎么到达那里的

相关内容

  • 没有找到相关文章

最新更新