apkbuilder finds duplicate file when adding powermock to an android test project

匆匆过客 提交于 2020-01-02 04:40:11

问题


I'm attempting to add powermock-mockito and mockito into an Android Test project. I created the android test project using the android command-line tool to create the build.xml and project structure. I have the following jars in my libs/ directory:

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

When I attempt to build the project with ant debug, I get the following error:

[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

I'm not sure how it's finding a duplicate file in a single jar. The build.xml file hasn't been modified at all and I haven't created a custom_rules.xml. Any help would be greatly appreciated.


回答1:


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.



回答2:


Have you checked if the file really is duplicated in the jar file? Afaik it is possible to have the same file twice in a zip file. In that file removing that from the jar could help. No idea how it would get there though.



来源:https://stackoverflow.com/questions/15796858/apkbuilder-finds-duplicate-file-when-adding-powermock-to-an-android-test-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!