Re: [powermock] Using PowerMock and Mockito in an Android Instrumentation test - Error - Duplicate files - org.mockito.plugins.MockMaker

2,314 views
Skip to first unread message
Message has been deleted

Johan Haleby

unread,
Feb 18, 2016, 3:04:06 AM2/18/16
to powe...@googlegroups.com
Hmm PowerMock doesn't work when running the tests on the device. I don't know what you mean by "Android instrumented tests" though. If they are executed using the DalvikVM then it won't work since PowerMock is using byte-code manipulation that requires a JVM.

On Wed, Feb 17, 2016 at 11:25 PM, 'Kai Armer' via PowerMock <powe...@googlegroups.com> wrote:
Hi everyone,

I'm having trouble using Android, Mockito and Powermock. In a nutshell I wish to mock a static method, for an Android Instrumentation test (to be ran on the device). When gradle tries to build the test apk (when running an Android instrumentation test) I get this error:

com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK mockito-extensions/org.mockito.plugins.MockMaker
File1: /Users/kaiarmer/.gradle/caches/modules-2/files-2.1/com.crittercism.dexmaker/dexmaker-mockito/1.4/70892a94894462c1b35df3c8a77d21b7e843550b/dexmaker-mockito-1.4.jar
File2: /Users/kaiarmer/.gradle/caches/modules-2/files-2.1/org.powermock/powermock-api-mockito/1.6.4/fe12509b7e9e49d25131f4155145748a31e42e40/powermock-api-mockito-1.6.4.jar

I've tried a lot of things to resolve this and I've published a comprehensive stack overflow post. I'd be grateful to anyone who could have a look and see if they could shed any light please:


Thanks in advance

Kai



--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To unsubscribe from this group and stop receiving emails from it, send an email to powermock+...@googlegroups.com.
To post to this group, send email to powe...@googlegroups.com.
Visit this group at https://groups.google.com/group/powermock.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Johan Haleby

unread,
Feb 22, 2016, 11:20:43 PM2/22/16
to powe...@googlegroups.com
Hi, 

Yes I also think other have got this to work but unfortunately I don't really know how. If you get it working perhaps you would be willing to help out and improve the docs?

Regards,
/Johan 

On Mon, Feb 22, 2016 at 11:47 AM, 'Kai Armer' via PowerMock <powe...@googlegroups.com> wrote:
Hi Johan,
Thanks for the reply.
An instrumentation test (in the Android world) is a test that runs on a device (or emulator) and interacts with the Android framework, rather than say just testing a stand-alone java utility class, which conversely could be done on the jvm.
My understanding is that some others have managed to get this to work with the Android framework by removing the duplicates from the offending jars manually (or using Maven's 'ignore duplicates' feature) and using the dexmaker libraries to convert to dex. The libraries in question are: 
androidTestCompile 'com.crittercism.dexmaker:dexmaker:1.4'
androidTestCompile 'com.crittercism.dexmaker:dexmaker-mockito:1.4'

Thanks.
Kai.
Message has been deleted

Johan Haleby

unread,
Feb 24, 2016, 2:19:53 AM2/24/16
to powe...@googlegroups.com
That's great Kai! PowerMock needs help from the community so it would be really appreciated if you want to help out and contribute.

On Tue, Feb 23, 2016 at 10:16 PM, 'Kai Armer' via PowerMock <powe...@googlegroups.com> wrote:
Hi Johan,
I'm still trying to get this working - think I have gotten a little further as it seems to be trying to dex the classes up but failing due to multiple versions of a class from the dependency jars. I've pushed up a commit to include this work (within my test app). I'll keep going (in my spare time) and of course I'm happy to contribute if I can.
Thanks,
Kai

vincenzo dc

unread,
May 12, 2016, 9:17:55 AM5/12/16
to PowerMock
Did you solve the problem? 
In Android you can tell to exclude duplicates by put this into your gradle file:
packagingOptions {
        exclude
'nameOfTheFileCausingProblem'
}


I'me using Easymock + Powermock to run instrumentation tests, but I'm facing another problem, after I solved the duplicated files
java.lang.IllegalStateException: Extension API internal error: org.powermock.api.extension.proxyframework.ProxyFrameworkImpl could not be located in classpath.


Yadnesh Phadke

unread,
Feb 21, 2017, 12:47:51 AM2/21/17
to PowerMock
I am also facing the same error "ProxyFrameworkImpl could not be located in classpath".  I have ensured that the class is present in the APK that is installed on the device for running the tests.  

Does anyone have any hints for resolving the issue?

Regards,
Yadnesh
Reply all
Reply to author
Forward
0 new messages