5

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.

Jearil
  • 126
  • 6

2 Answers2

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.
Lee
  • 18,529
  • 6
  • 58
  • 60
nparihar
  • 31
  • 2
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.

koljaTM
  • 10,064
  • 2
  • 40
  • 42
  • It didn't exist more than once. I think ultimately the problem lies with androids default testing framework not working with anything that does byte-level manipulation like mocking frameworks. I may have to try something else to be able to do any reasonable TDD in android. – Jearil Apr 24 '13 at 20:44
  • I had this exact same problem and indeed, the powermock-mockito-1.5-full.jar had a duplicate file called "org.mockito.plugins.MockMaker" under "mockito-extensions" folder. I mean c'mon, I wasted hours on debugging this. The library was released last December and there's still a ridiculous issue like this present. Jeez.. – gelupa Jun 04 '13 at 09:35