apkbuilder finds duplicate file when adding powerm

2019-04-30 02:34发布

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.

2条回答
对你真心纯属浪费
2楼-- · 2019-04-30 02:50

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.
查看更多
对你真心纯属浪费
3楼-- · 2019-04-30 02:55

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.

查看更多
登录 后发表回答