Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 253
Jearil Avatar asked Apr 03 '13 19:04

Jearil


2 Answers

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.
like image 131
nparihar Avatar answered Sep 22 '22 13:09

nparihar


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.

like image 32
koljaTM Avatar answered Sep 21 '22 13:09

koljaTM