Apkbuilder finds duplicate file when adding powermock to Android test project

I am trying to add powermock-mockito and mockito to an Android Test project. I created an Android test project using the android command line tool to create build.xml and project structure. I have the following banks in the 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 try to create a project using 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 am not sure how to find a duplicate file in one bank. The build.xml file was not modified at all, and I did not create custom_rules.xml. Any help would be greatly appreciated.

+5
android unit-testing mockito powermock
source share
2 answers

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

  • Make a backup of powermock-mockito-1.5-full.jar
  • Rename powermock-mockito-1.5-full.jar to powermock-mockito-1.5-full.zip
  • powermock-mockito-1.5-full.zip
  • rm -rf mockito-extensions
  • jar cf powermock-mockito-1.5-full.jar META-INF/ org/
  • Place the updated jar in the libs folder.
+3
source share

Have you checked if the file is really duplicated in the jar file? Afaik can have the same file twice in a zip file. Removing this from the jar may help in this file. I don’t know how it happened, though.

+2
source share

All Articles