Android support #53

Closed
yogurtearl opened this Issue Sep 18, 2013 · 43 comments

Comments

Projects
None yet
@yogurtearl

Any plans for Android support? I tried it and it didn't work out of the box.

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst Sep 19, 2013

Owner

It's not on the list currently. Is there a reason you can't run it on your laptop and point the Android app at that?

Owner

tomakehurst commented Sep 19, 2013

It's not on the list currently. Is there a reason you can't run it on your laptop and point the Android app at that?

@stephanenicolas

This comment has been minimized.

Show comment
Hide comment
@stephanenicolas

stephanenicolas Oct 7, 2013

Usually, a mock server runs on the Android device itself. I can't say for @tomakehurst , but such a usage (on a desktop) while the android tests run on device/emulator would be quite tough to setup and even more to industrialize.

The best solution is really to be able to run the mock web server on the device itself.

Usually, a mock server runs on the Android device itself. I can't say for @tomakehurst , but such a usage (on a desktop) while the android tests run on device/emulator would be quite tough to setup and even more to industrialize.

The best solution is really to be able to run the mock web server on the device itself.

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst Oct 8, 2013

Owner

I'm surprised to hear that. I'd be interested to know why this is difficult.

I haven't done all that much mobile development, but when I have there's always been a server available over wi-fi in the test setup, and when I've needed mock responses I've run hosted them on this.

If an Android build would be genuinely helpful, then I'm more than happy to have this as part of the project. I probably lack the experience with Android development to make this happen any time soon though, so I'd welcome any contributions in this area.

Owner

tomakehurst commented Oct 8, 2013

I'm surprised to hear that. I'd be interested to know why this is difficult.

I haven't done all that much mobile development, but when I have there's always been a server available over wi-fi in the test setup, and when I've needed mock responses I've run hosted them on this.

If an Android build would be genuinely helpful, then I'm more than happy to have this as part of the project. I probably lack the experience with Android development to make this happen any time soon though, so I'd welcome any contributions in this area.

@stephanenicolas

This comment has been minimized.

Show comment
Hide comment
@stephanenicolas

stephanenicolas Oct 8, 2013

Suppose you use an Android and a laptop on the same WAN. Chances are that
the router will isolate hosts, and then that's over. Moreover, from an
industrialization perspective, it would be very hard to inject the ip
adress of the CI server into the app under test on an emulator/device.

The best is really to embed the webserver.

2013/10/8 tomakehurst notifications@github.com

I'm surprised to hear that. I'd be interested to know why this is
difficult.

I haven't done all that much mobile development, but when I have there's
always been a server available over wi-fi in the test setup, and when I've
needed mock responses I've run hosted them on this.

If an Android build would be genuinely helpful, then I'm more than happy
to have this as part of the project. I probably lack the experience with
Android development to make this happen any time soon though, so I'd
welcome any contributions in this area.


Reply to this email directly or view it on GitHubhttps://github.com/tomakehurst/wiremock/issues/53#issuecomment-25881086
.

Stéphane NICOLAS,
OCTO Technology
Développeur & Consultant Android / Java
..........................................................
50, Avenue des Champs-Elysées
75008 Paris
+33 (0)6.26.32.34.09
www.octo.com - mobilite.octo.com
blog.octo.com - www.usievents.com
...........................................................

Suppose you use an Android and a laptop on the same WAN. Chances are that
the router will isolate hosts, and then that's over. Moreover, from an
industrialization perspective, it would be very hard to inject the ip
adress of the CI server into the app under test on an emulator/device.

The best is really to embed the webserver.

2013/10/8 tomakehurst notifications@github.com

I'm surprised to hear that. I'd be interested to know why this is
difficult.

I haven't done all that much mobile development, but when I have there's
always been a server available over wi-fi in the test setup, and when I've
needed mock responses I've run hosted them on this.

If an Android build would be genuinely helpful, then I'm more than happy
to have this as part of the project. I probably lack the experience with
Android development to make this happen any time soon though, so I'd
welcome any contributions in this area.


Reply to this email directly or view it on GitHubhttps://github.com/tomakehurst/wiremock/issues/53#issuecomment-25881086
.

Stéphane NICOLAS,
OCTO Technology
Développeur & Consultant Android / Java
..........................................................
50, Avenue des Champs-Elysées
75008 Paris
+33 (0)6.26.32.34.09
www.octo.com - mobilite.octo.com
blog.octo.com - www.usievents.com
...........................................................

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst Oct 8, 2013

Owner

Certainly if your routers behave like that and your network team won't help out then that's a problem. My experience has been that you can usually find a way to get wi-fi working how you need it (even if it means setting your laptop up as an ad-hoc network).

I've handled the IP resolution issue in a couple of ways in the past: 1) by configuring local DNS to return the test server, 2) by creating an extra settings field for the server host which is only visible in dev builds.

Owner

tomakehurst commented Oct 8, 2013

Certainly if your routers behave like that and your network team won't help out then that's a problem. My experience has been that you can usually find a way to get wi-fi working how you need it (even if it means setting your laptop up as an ad-hoc network).

I've handled the IP resolution issue in a couple of ways in the past: 1) by configuring local DNS to return the test server, 2) by creating an extra settings field for the server host which is only visible in dev builds.

@stephanenicolas

This comment has been minimized.

Show comment
Hide comment
@stephanenicolas

stephanenicolas Oct 8, 2013

That's fine for me Tomas. Sorry to have disturbed, but on Android I prefer
to use mockwebserver. It's easier to handle according to my experience.

2013/10/8 tomakehurst notifications@github.com

Certainly if your routers behave like that and your network team won't
help out then that's a problem. My experience has been that you can usually
find a way to get wi-fi working how you need it (even if it means setting
your laptop up as an ad-hoc network).

I've handled the IP resolution issue in a couple of ways in the past: 1)
by configuring local DNS to return the test server, 2) by creating an extra
settings field for the server host which is only visible in dev builds.


Reply to this email directly or view it on GitHubhttps://github.com/tomakehurst/wiremock/issues/53#issuecomment-25884975
.

Stéphane NICOLAS,
OCTO Technology
Développeur & Consultant Android / Java
..........................................................
50, Avenue des Champs-Elysées
75008 Paris
+33 (0)6.26.32.34.09
www.octo.com - mobilite.octo.com
blog.octo.com - www.usievents.com
...........................................................

That's fine for me Tomas. Sorry to have disturbed, but on Android I prefer
to use mockwebserver. It's easier to handle according to my experience.

2013/10/8 tomakehurst notifications@github.com

Certainly if your routers behave like that and your network team won't
help out then that's a problem. My experience has been that you can usually
find a way to get wi-fi working how you need it (even if it means setting
your laptop up as an ad-hoc network).

I've handled the IP resolution issue in a couple of ways in the past: 1)
by configuring local DNS to return the test server, 2) by creating an extra
settings field for the server host which is only visible in dev builds.


Reply to this email directly or view it on GitHubhttps://github.com/tomakehurst/wiremock/issues/53#issuecomment-25884975
.

Stéphane NICOLAS,
OCTO Technology
Développeur & Consultant Android / Java
..........................................................
50, Avenue des Champs-Elysées
75008 Paris
+33 (0)6.26.32.34.09
www.octo.com - mobilite.octo.com
blog.octo.com - www.usievents.com
...........................................................

@letz

This comment has been minimized.

Show comment
Hide comment
@letz

letz May 19, 2014

Any developments regarding mock web server in the device itself?

letz commented May 19, 2014

Any developments regarding mock web server in the device itself?

@yogurtearl

This comment has been minimized.

Show comment
Hide comment
@yogurtearl

yogurtearl May 20, 2014

It is possible with a bit of work. :)

It is possible with a bit of work. :)

@letz

This comment has been minimized.

Show comment
Hide comment
@letz

letz May 20, 2014

can you give me some guidelines?

letz commented May 20, 2014

can you give me some guidelines?

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst May 20, 2014

Owner

I'm considering a refactoring to support multiple web servers, such that the Android fork of Jetty could be used. I'll start a discussion about this on the Google group, perhaps you'd all like to join so that you can participate?

Owner

tomakehurst commented May 20, 2014

I'm considering a refactoring to support multiple web servers, such that the Android fork of Jetty could be used. I'll start a discussion about this on the Google group, perhaps you'd all like to join so that you can participate?

@letz

This comment has been minimized.

Show comment
Hide comment
@letz

letz May 20, 2014

thats fine be me :)

letz commented May 20, 2014

thats fine be me :)

@letz

This comment has been minimized.

Show comment
Hide comment
@letz

letz Jun 2, 2014

@tomakehurst any developments?

letz commented Jun 2, 2014

@tomakehurst any developments?

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst Jun 3, 2014

Owner

I've just started a new job, so I've had no time to work on this.

Can I suggest you join the mailing list if you haven't already? I'm planning to start a thread about what to include in the next wave of development.

Owner

tomakehurst commented Jun 3, 2014

I've just started a new job, so I've had no time to work on this.

Can I suggest you join the mailing list if you haven't already? I'm planning to start a thread about what to include in the next wave of development.

@letz

This comment has been minimized.

Show comment
Hide comment
@letz

letz Jun 3, 2014

I already joined the mailing list. Meanwhile @yogurtearl can you explain how did you do it?

letz commented Jun 3, 2014

I already joined the mailing list. Meanwhile @yogurtearl can you explain how did you do it?

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst Jun 4, 2014

Owner

I'd also be very interested to hear about this (preferably on the mailing list!).

Owner

tomakehurst commented Jun 4, 2014

I'd also be very interested to hear about this (preferably on the mailing list!).

@objcode

This comment has been minimized.

Show comment
Hide comment
@objcode

objcode Oct 1, 2014

Also looking into this. +1 on adding it out of box.

objcode commented Oct 1, 2014

Also looking into this. +1 on adding it out of box.

@objcode

This comment has been minimized.

Show comment
Hide comment
@objcode

objcode Oct 2, 2014

I did part of the work to get it to run on Android:

#178

You'll still need to update the javax dependencies that aren't available on Android. I'm going to go down the path of hosting it on the desktop of my emulator for now.

objcode commented Oct 2, 2014

I did part of the work to get it to run on Android:

#178

You'll still need to update the javax dependencies that aren't available on Android. I'm going to go down the path of hosting it on the desktop of my emulator for now.

@Rodney-QAGeek

This comment has been minimized.

Show comment
Hide comment
@Rodney-QAGeek

Rodney-QAGeek Nov 25, 2014

+1 on adding it out of box.

I've been having some trouble getting it configured properly as well. I'd love to hear how @yogurtearl got it working. He mentioned it again recently during his presentation at GTAC 2014. (Fast forward to 29:15)

+1 on adding it out of box.

I've been having some trouble getting it configured properly as well. I'd love to hear how @yogurtearl got it working. He mentioned it again recently during his presentation at GTAC 2014. (Fast forward to 29:15)

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst Dec 6, 2014

Owner

He's keeping his cards close to his chest on that one :-)

We're a few steps closer to OOTB Android support with the logging changes that went in recently. Just need to find the time for a final push.

Owner

tomakehurst commented Dec 6, 2014

He's keeping his cards close to his chest on that one :-)

We're a few steps closer to OOTB Android support with the logging changes that went in recently. Just need to find the time for a final push.

@indraneel76

This comment has been minimized.

Show comment
Hide comment
@indraneel76

indraneel76 Feb 5, 2015

Hi

I tried integrating wiremock standalone jar with my android project and got error where its complaining about missing javax.naming.ldap.LdapName'.

02-05 04:01:50.100: E/dalvikvm(2944): Could not find class 'javax.naming.ldap.LdapName', referenced from method wiremock.org.apache.http.conn.ssl.AbstractVerifier.extractCNs

Hi

I tried integrating wiremock standalone jar with my android project and got error where its complaining about missing javax.naming.ldap.LdapName'.

02-05 04:01:50.100: E/dalvikvm(2944): Could not find class 'javax.naming.ldap.LdapName', referenced from method wiremock.org.apache.http.conn.ssl.AbstractVerifier.extractCNs

@indraneel76

This comment has been minimized.

Show comment
Hide comment
@indraneel76

indraneel76 Feb 5, 2015

I think I have got a bit of success now using Objcode's modification. I have not used gradle to build the android project but instead not the jars manually and built the android project.

You can access the android project at https://www.dropbox.com/s/ityzj8co7k0yrgt/MyProjectWithWireMock.zip?dl=0

This are the steps to run the program -

  1. unzip the file from dropbox and import it into eclipse as android project
  2. start the standalone wiremock on the laptop -
    java -jar wiremock-1.53-standalone.jar --port 8888 --verbose
  3. Run the android project on a emulator
  4. The small app should open up on emulator with SendRequest button
  5. click on sendRequest button and you would see a response from WireMock.

To run this on real device , you need to change 10.0.2.2 (the way emulator sees the laptop) to actual ip address of the laptop . both real device and laptop needs to be on wifi.

I hope it helps some one..

I also tried running wiremock as server on android device itself , but that failed due to some jetty issues (i have put jetty jar in libs folder of android .. but showed link to class error)

I think I have got a bit of success now using Objcode's modification. I have not used gradle to build the android project but instead not the jars manually and built the android project.

You can access the android project at https://www.dropbox.com/s/ityzj8co7k0yrgt/MyProjectWithWireMock.zip?dl=0

This are the steps to run the program -

  1. unzip the file from dropbox and import it into eclipse as android project
  2. start the standalone wiremock on the laptop -
    java -jar wiremock-1.53-standalone.jar --port 8888 --verbose
  3. Run the android project on a emulator
  4. The small app should open up on emulator with SendRequest button
  5. click on sendRequest button and you would see a response from WireMock.

To run this on real device , you need to change 10.0.2.2 (the way emulator sees the laptop) to actual ip address of the laptop . both real device and laptop needs to be on wifi.

I hope it helps some one..

I also tried running wiremock as server on android device itself , but that failed due to some jetty issues (i have put jetty jar in libs folder of android .. but showed link to class error)

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst Feb 5, 2015

Owner

Thanks for posting this.

Unfortunately, some of the libraries used by WireMock don't work on the Android JVM. Some other folks have had some success with private Android forks, including @yogurtearl , but I've not yet found the time to create an official one, although I'd like to do this.

Owner

tomakehurst commented Feb 5, 2015

Thanks for posting this.

Unfortunately, some of the libraries used by WireMock don't work on the Android JVM. Some other folks have had some success with private Android forks, including @yogurtearl , but I've not yet found the time to create an official one, although I'd like to do this.

@indraneel76

This comment has been minimized.

Show comment
Hide comment
@indraneel76

indraneel76 Feb 6, 2015

Finally Thanks to Tom for making this wonderful tool and Sean (objcode) for making it android compatible. It is a very useful tool for me ...and would save lot of time in developing android app.

Finally Thanks to Tom for making this wonderful tool and Sean (objcode) for making it android compatible. It is a very useful tool for me ...and would save lot of time in developing android app.

@arkangelx

This comment has been minimized.

Show comment
Hide comment
@arkangelx

arkangelx Feb 16, 2015

Hi, getting this error and others
02-16 15:18:26.133: E/AndroidRuntime(7180): java.lang.NoClassDefFoundError: org.mortbay.jetty.Server
02-16 15:18:26.133: E/AndroidRuntime(7180): at com.github.tomakehurst.wiremock.WireMockServer.start(WireMockServer.java:178)

Hi, getting this error and others
02-16 15:18:26.133: E/AndroidRuntime(7180): java.lang.NoClassDefFoundError: org.mortbay.jetty.Server
02-16 15:18:26.133: E/AndroidRuntime(7180): at com.github.tomakehurst.wiremock.WireMockServer.start(WireMockServer.java:178)

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst Feb 16, 2015

Owner

As I mentioned earlier in this thread, WireMock does not currently work with Android without modification.

Owner

tomakehurst commented Feb 16, 2015

As I mentioned earlier in this thread, WireMock does not currently work with Android without modification.

@flyfeihuang

This comment has been minimized.

Show comment
Hide comment
@flyfeihuang

flyfeihuang Mar 18, 2015

So bad ,I try it run in Andriod platform two days,but it don't work

So bad ,I try it run in Andriod platform two days,but it don't work

@indraneel76

This comment has been minimized.

Show comment
Hide comment
@indraneel76

indraneel76 Mar 18, 2015

Hi
I can help you on this as the error looks familiar to me
.. you need to get some lib files in your directory like jetty
go to https://www.dropbox.com/s/ityzj8co7k0yrgt/MyProjectWithWireMock.zip?dl=0

unzip the zip file , there will be a libs folder inside . Get those libs as reference in your project as well
Also do have a folder in your project called libs with all those jars. Android run time picks up jars from libs folder . Your error points out that it didn't get jetty jar file . Reply back if you still have issues..

enjoy
Indraneel

Hi
I can help you on this as the error looks familiar to me
.. you need to get some lib files in your directory like jetty
go to https://www.dropbox.com/s/ityzj8co7k0yrgt/MyProjectWithWireMock.zip?dl=0

unzip the zip file , there will be a libs folder inside . Get those libs as reference in your project as well
Also do have a folder in your project called libs with all those jars. Android run time picks up jars from libs folder . Your error points out that it didn't get jetty jar file . Reply back if you still have issues..

enjoy
Indraneel

@mike011

This comment has been minimized.

Show comment
Hide comment
@mike011

mike011 Oct 30, 2015

Updated for android studio, junit4, and espresso.

https://github.com/mike011/Wiremock_Android_Example

mike011 commented Oct 30, 2015

Updated for android studio, junit4, and espresso.

https://github.com/mike011/Wiremock_Android_Example

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst Oct 30, 2015

Owner

Looks interesting, thanks for sharing!

Owner

tomakehurst commented Oct 30, 2015

Looks interesting, thanks for sharing!

@handstandsam

This comment has been minimized.

Show comment
Hide comment
@handstandsam

handstandsam Jan 6, 2016

Contributor

WireMock now supports Android as of 2.0.8-beta.
Thanks to everyone for their tips/examples. The updates done in the 2.0-beta branch fixed a lot of the dependency issues that hindered Android support in the 1.0 branch. I added a small method signature change that was the last piece of the puzzle to get full support: df2ccc6

You can see an example project I made running WireMock in some test cases here: https://github.com/handstandsam/AndroidHttpMockingExamples

Gradle Dependencies:

//WireMock Dependencies
androidTestCompile("com.github.tomakehurst:wiremock:2.0.8-beta") {
    //Allows us to use the Android version of Apache httpclient instead
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'

    //Resolves the Duplicate Class Exception
    //Error:Execution failed for task ':app:transformClassesWithJarMergingForDebugAndroidTest'.
    //       > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/objectweb/asm/AnnotationVisitor.class
    exclude group: 'asm', module: 'asm'
}
androidTestCompile 'org.apache.httpcomponents:httpclient-android:4.3.5+'

This issue can be marked as resolved.

Contributor

handstandsam commented Jan 6, 2016

WireMock now supports Android as of 2.0.8-beta.
Thanks to everyone for their tips/examples. The updates done in the 2.0-beta branch fixed a lot of the dependency issues that hindered Android support in the 1.0 branch. I added a small method signature change that was the last piece of the puzzle to get full support: df2ccc6

You can see an example project I made running WireMock in some test cases here: https://github.com/handstandsam/AndroidHttpMockingExamples

Gradle Dependencies:

//WireMock Dependencies
androidTestCompile("com.github.tomakehurst:wiremock:2.0.8-beta") {
    //Allows us to use the Android version of Apache httpclient instead
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'

    //Resolves the Duplicate Class Exception
    //Error:Execution failed for task ':app:transformClassesWithJarMergingForDebugAndroidTest'.
    //       > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/objectweb/asm/AnnotationVisitor.class
    exclude group: 'asm', module: 'asm'
}
androidTestCompile 'org.apache.httpcomponents:httpclient-android:4.3.5+'

This issue can be marked as resolved.

@handstandsam

This comment has been minimized.

Show comment
Hide comment
@handstandsam

handstandsam Jan 7, 2016

Contributor

Figured out you also need to exclude org.json:json because Android already has a version. I updated the build.grade for the sample project here.

Contributor

handstandsam commented Jan 7, 2016

Figured out you also need to exclude org.json:json because Android already has a version. I updated the build.grade for the sample project here.

@davidgouldsky

This comment has been minimized.

Show comment
Hide comment
@davidgouldsky

davidgouldsky May 26, 2016

It certainly looks promising; unfortunately I've encountered a number of reliability issues when using it in integration testing. If anybody would like some information to assist in improving the product, please let me know.

It certainly looks promising; unfortunately I've encountered a number of reliability issues when using it in integration testing. If anybody would like some information to assist in improving the product, please let me know.

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst May 26, 2016

Owner

Hi David,

I'm always interested to receive useful feedback.

Have you discovered some specific bugs? If so, would you mind raising them as Github issues?

Many thanks,
Tom

Owner

tomakehurst commented May 26, 2016

Hi David,

I'm always interested to receive useful feedback.

Have you discovered some specific bugs? If so, would you mind raising them as Github issues?

Many thanks,
Tom

@ghdbre

This comment has been minimized.

Show comment
Hide comment
@ghdbre

ghdbre Oct 18, 2016

Using WireMock 2.2.1 I had to specify
"exclude group: 'org.ow2.asm', module: 'asm'" and not
"exclude group: 'asm', module: 'asm'"
in handstandsam's build.gradle to get rid of the the error "ZipException: duplicate entry: org/objectweb/asm/AnnotationVisitor.class"

ghdbre commented Oct 18, 2016

Using WireMock 2.2.1 I had to specify
"exclude group: 'org.ow2.asm', module: 'asm'" and not
"exclude group: 'asm', module: 'asm'"
in handstandsam's build.gradle to get rid of the the error "ZipException: duplicate entry: org/objectweb/asm/AnnotationVisitor.class"

@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst Oct 18, 2016

Owner

Thanks for sharing that. Perhaps worth posting a comment on Sam's blog?

Owner

tomakehurst commented Oct 18, 2016

Thanks for sharing that. Perhaps worth posting a comment on Sam's blog?

@ghdbre

This comment has been minimized.

Show comment
Hide comment
@ghdbre

ghdbre Oct 18, 2016

Tried - only twitter users qualify.

Relying on GitHub's auto-mail feature.

ghdbre commented Oct 18, 2016

Tried - only twitter users qualify.

Relying on GitHub's auto-mail feature.

@alexei28

This comment has been minimized.

Show comment
Hide comment
@alexei28

alexei28 Apr 27, 2017

Android Studio 2.3.1.
My build.gradle (dependency).

`dependencies {
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.volley:volley:1.0.0'

// for folder "androidTest"
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile "org.mockito:mockito-android:2.7.21"
androidTestCompile "org.powermock:powermock-api-mockito:1.6.6"
androidTestCompile 'org.powermock:powermock-module-junit4:1.6.6'

// for folder "test"
testCompile 'junit:junit:4.12'
testCompile 'org.powermock:powermock-api-mockito:1.6.6'
testCompile 'org.powermock:powermock-module-junit4:1.6.6'
testCompile "org.mockito:mockito-core:+"

//WireMock
androidTestCompile("com.github.tomakehurst:wiremock:2.6.0") {
    //Using Android Version Instead
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'

    //Version conflict with our app's slf4j version
    exclude group: 'org.slf4j', module: 'slf4j-api'

    //Was getting a classpath conflict for org.objectweb.asm.AnnotationVisitor which is a part of 'net.minidev:asm'
    exclude group: 'org.ow2.asm', module: 'asm'

    //Was getting this warning, so decided to ignore this version included by WireMock.
    //Warning:Dependency org.json:json:20090211 is ignored as it may be conflicting with the internal version provided by Android.
    //In case of problem, please repackage with jarjar to change the class packages
    exclude group: 'org.json', module: 'json'
}

}`

But when I try to start Android instrumented unit test (from folder "androidTest") I get the next error:

`Error:Execution failed for task ':app:transformClassesWithDexForDevAndroidTest'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
`

Android Studio 2.3.1.
My build.gradle (dependency).

`dependencies {
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.volley:volley:1.0.0'

// for folder "androidTest"
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile "org.mockito:mockito-android:2.7.21"
androidTestCompile "org.powermock:powermock-api-mockito:1.6.6"
androidTestCompile 'org.powermock:powermock-module-junit4:1.6.6'

// for folder "test"
testCompile 'junit:junit:4.12'
testCompile 'org.powermock:powermock-api-mockito:1.6.6'
testCompile 'org.powermock:powermock-module-junit4:1.6.6'
testCompile "org.mockito:mockito-core:+"

//WireMock
androidTestCompile("com.github.tomakehurst:wiremock:2.6.0") {
    //Using Android Version Instead
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'

    //Version conflict with our app's slf4j version
    exclude group: 'org.slf4j', module: 'slf4j-api'

    //Was getting a classpath conflict for org.objectweb.asm.AnnotationVisitor which is a part of 'net.minidev:asm'
    exclude group: 'org.ow2.asm', module: 'asm'

    //Was getting this warning, so decided to ignore this version included by WireMock.
    //Warning:Dependency org.json:json:20090211 is ignored as it may be conflicting with the internal version provided by Android.
    //In case of problem, please repackage with jarjar to change the class packages
    exclude group: 'org.json', module: 'json'
}

}`

But when I try to start Android instrumented unit test (from folder "androidTest") I get the next error:

`Error:Execution failed for task ':app:transformClassesWithDexForDevAndroidTest'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
`

@handstandsam

This comment has been minimized.

Show comment
Hide comment
@handstandsam

handstandsam May 14, 2017

Contributor

Yeah, you need Multidex enabled like the sample app unfortunately. Sorry for the late response. Your test apk can't actually go over the Dec, otherwise it won't find those classes in the 2nd dex. This isn't a problem on 21+ for tests.

Contributor

handstandsam commented May 14, 2017

Yeah, you need Multidex enabled like the sample app unfortunately. Sorry for the late response. Your test apk can't actually go over the Dec, otherwise it won't find those classes in the 2nd dex. This isn't a problem on 21+ for tests.

@lmdic

This comment has been minimized.

Show comment
Hide comment
@lmdic

lmdic May 19, 2017

Android, Gradle, Espresso: When add WireMode get error: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'

My Android Espresso test:

package com.example.testproject;

import android.content.Context;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.core.IsNot.not;

@RunWith(AndroidJUnit4.class)
public class MainActivityTest {
    private static String TAG;
    private Context context;

    @Rule
    public ActivityTestRule<MainActivity_> mActivityRule = new ActivityTestRule<>(MainActivity_.class);

    @Before
    public void init() {
        TAG = MainActivity.class.getName();
        context = mActivityRule.getActivity();
    }

    @Test
    public void checkClick() {
        onView(withId(R.id.myButton)).perform(click());
        onView(withId(R.id.myTextView)).check(matches(withText(R.string.you_click)));
    }
}

My build.gradle:

apply plugin: 'com.android.application'

`android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.testproject"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        // Enabling Multidex support for 'androidTest' builds because of large dependencies
        // need for androidTest
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'

        exclude 'mockito-extensions/org.mockito.plugins.MockMaker'
    }
}

def AAVersion = '4.3.0'

dependencies {

    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    compile 'us.feras.mdv:markdownview:1.1.0'
    compile 'com.github.mukeshsolanki:MarkdownView-Android:1.0.3'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile group: 'commons-io', name: 'commons-io', version: '2.4'

    androidTestCompile 'junit:junit:4.12'
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.google.guava', module: 'guava'
        exclude group: 'junit', module: 'junit'
    }
}

`

I run Espresso test (checkClick) by gradle from command line:

gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.testproject.MainActivityTest#checkClick

and Espresso test success run and execute. OK!

Now I want to use lib WireMock to test http request/response. So I change my dependencies in build.gradle:

dependencies {

    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    compile 'us.feras.mdv:markdownview:1.1.0'
    compile 'com.github.mukeshsolanki:MarkdownView-Android:1.0.3'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile group: 'commons-io', name: 'commons-io', version: '2.4'

    androidTestCompile 'junit:junit:4.12'
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.google.guava', module: 'guava'
        exclude group: 'junit', module: 'junit'
    }

    //WireMock
    androidTestCompile("com.github.tomakehurst:wiremock:2.5.0") {
        //Using Android Version Instead
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'

        //Version conflict with our app's slf4j version
        exclude group: 'org.slf4j', module: 'slf4j-api'

        //Was getting a classpath conflict for org.objectweb.asm.AnnotationVisitor which is a part of 'net.minidev:asm'
        exclude group: 'org.ow2.asm', module: 'asm'

        //Was getting this warning, so decided to ignore this version included by WireMock.
        //Warning:Dependency org.json:json:20090211 is ignored as it may be conflicting with the internal version provided by Android.
        //In case of problem, please repackage with jarjar to change the class packages
        exclude group: 'org.json', module: 'json'
    }
    androidTestCompile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    androidTestCompile 'commons-io:commons-io:2.4'
}

And now when I run same Espresso test I get error:

gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.testproject.MainActivityTest#checkClick --debug --stacktrace

...
:app:assembleDebugAndroidTest UP-TO-DATE
:app:connectedDebugAndroidTest
Starting 0 tests on Galaxy Nexus - 4.3
Tests on Galaxy Nexus - 4.3 failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'

com.android.builder.testing.ConnectedDevice > No tests found.[Galaxy Nexus - 4.3] FAILED 
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).
:app:connectedDebugAndroidTest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:connectedDebugAndroidTest'.
> There were failing tests. See the report at: file:///D:/dev/mobile/TestProject/app/build/reports/androidTests/connected/index.html

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:connectedDebugAndroidTest'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:84)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
    at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:196)
    at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:193)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:193)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
    at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
    at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.api.GradleException: There were failing tests. See the report at: file:///D:/dev/mobile/TestProject/app/build/reports/androidTests/connected/index.html
    at com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask.runTests(DeviceProviderInstrumentTestTask.java:160)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.doExecute(DefaultTaskClassInfoStore.java:141)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:632)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:615)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
    ... 70 more


BUILD FAILED

I get same error when try to run Espresso test from Android Studio 2.3

lmdic commented May 19, 2017

Android, Gradle, Espresso: When add WireMode get error: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'

My Android Espresso test:

package com.example.testproject;

import android.content.Context;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.core.IsNot.not;

@RunWith(AndroidJUnit4.class)
public class MainActivityTest {
    private static String TAG;
    private Context context;

    @Rule
    public ActivityTestRule<MainActivity_> mActivityRule = new ActivityTestRule<>(MainActivity_.class);

    @Before
    public void init() {
        TAG = MainActivity.class.getName();
        context = mActivityRule.getActivity();
    }

    @Test
    public void checkClick() {
        onView(withId(R.id.myButton)).perform(click());
        onView(withId(R.id.myTextView)).check(matches(withText(R.string.you_click)));
    }
}

My build.gradle:

apply plugin: 'com.android.application'

`android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.testproject"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        // Enabling Multidex support for 'androidTest' builds because of large dependencies
        // need for androidTest
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'

        exclude 'mockito-extensions/org.mockito.plugins.MockMaker'
    }
}

def AAVersion = '4.3.0'

dependencies {

    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    compile 'us.feras.mdv:markdownview:1.1.0'
    compile 'com.github.mukeshsolanki:MarkdownView-Android:1.0.3'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile group: 'commons-io', name: 'commons-io', version: '2.4'

    androidTestCompile 'junit:junit:4.12'
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.google.guava', module: 'guava'
        exclude group: 'junit', module: 'junit'
    }
}

`

I run Espresso test (checkClick) by gradle from command line:

gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.testproject.MainActivityTest#checkClick

and Espresso test success run and execute. OK!

Now I want to use lib WireMock to test http request/response. So I change my dependencies in build.gradle:

dependencies {

    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    compile 'us.feras.mdv:markdownview:1.1.0'
    compile 'com.github.mukeshsolanki:MarkdownView-Android:1.0.3'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile group: 'commons-io', name: 'commons-io', version: '2.4'

    androidTestCompile 'junit:junit:4.12'
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.google.guava', module: 'guava'
        exclude group: 'junit', module: 'junit'
    }

    //WireMock
    androidTestCompile("com.github.tomakehurst:wiremock:2.5.0") {
        //Using Android Version Instead
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'

        //Version conflict with our app's slf4j version
        exclude group: 'org.slf4j', module: 'slf4j-api'

        //Was getting a classpath conflict for org.objectweb.asm.AnnotationVisitor which is a part of 'net.minidev:asm'
        exclude group: 'org.ow2.asm', module: 'asm'

        //Was getting this warning, so decided to ignore this version included by WireMock.
        //Warning:Dependency org.json:json:20090211 is ignored as it may be conflicting with the internal version provided by Android.
        //In case of problem, please repackage with jarjar to change the class packages
        exclude group: 'org.json', module: 'json'
    }
    androidTestCompile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    androidTestCompile 'commons-io:commons-io:2.4'
}

And now when I run same Espresso test I get error:

gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.testproject.MainActivityTest#checkClick --debug --stacktrace

...
:app:assembleDebugAndroidTest UP-TO-DATE
:app:connectedDebugAndroidTest
Starting 0 tests on Galaxy Nexus - 4.3
Tests on Galaxy Nexus - 4.3 failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'

com.android.builder.testing.ConnectedDevice > No tests found.[Galaxy Nexus - 4.3] FAILED 
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).
:app:connectedDebugAndroidTest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:connectedDebugAndroidTest'.
> There were failing tests. See the report at: file:///D:/dev/mobile/TestProject/app/build/reports/androidTests/connected/index.html

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:connectedDebugAndroidTest'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:84)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
    at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:196)
    at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:193)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:193)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
    at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
    at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.api.GradleException: There were failing tests. See the report at: file:///D:/dev/mobile/TestProject/app/build/reports/androidTests/connected/index.html
    at com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask.runTests(DeviceProviderInstrumentTestTask.java:160)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.doExecute(DefaultTaskClassInfoStore.java:141)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:632)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:615)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
    ... 70 more


BUILD FAILED

I get same error when try to run Espresso test from Android Studio 2.3

@handstandsam

This comment has been minimized.

Show comment
Hide comment
@handstandsam

handstandsam May 19, 2017

Contributor

Looks like you hit Multidex issues for the test apk. Try on a 21+ device and it should work.

Contributor

handstandsam commented May 19, 2017

Looks like you hit Multidex issues for the test apk. Try on a 21+ device and it should work.

@lmdic

This comment has been minimized.

Show comment
Hide comment
@lmdic

lmdic May 20, 2017

I found solutions of problem:

  1. If you use Android 5.0- (e.g. Android 4.3) then you MUST use Wiremock version 2.0.8-beta

androidTestCompile 'com.github.tomakehurst:wiremock:2.0.8-beta'

  1. If you use Android 5.0+ you can you use any Wiremock version (e.g. 2.5.0)

androidTestCompile 'com.github.tomakehurst:wiremock:2.6.0'

P.S. Maybe this is a Multidex issues.

lmdic commented May 20, 2017

I found solutions of problem:

  1. If you use Android 5.0- (e.g. Android 4.3) then you MUST use Wiremock version 2.0.8-beta

androidTestCompile 'com.github.tomakehurst:wiremock:2.0.8-beta'

  1. If you use Android 5.0+ you can you use any Wiremock version (e.g. 2.5.0)

androidTestCompile 'com.github.tomakehurst:wiremock:2.6.0'

P.S. Maybe this is a Multidex issues.

@maximelebastard

This comment has been minimized.

Show comment
Hide comment
@maximelebastard

maximelebastard Jun 26, 2017

Ok but what if you want to use it on Android 5.0- AND Android 5.0+ ?

I can get Wiremock working on Android 5.0, but I still have a failure on :app:transformClassesWithMultidexlistForDebugAndroidTest task on Android 4.3

I also had to compile jetty-http aside, because the class HttpScheme from Jetty was not found on Android 4.3 (but was found on Android 5.0).

 // Wiremock
    androidTestCompile('com.github.tomakehurst:wiremock:2.0.8-beta') {
        //Using Android Version Instead
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'

        //Was getting a classpath conflict for org.objectweb.asm.AnnotationVisitor which is a part of 'net.minidev:asm'
        exclude group: 'asm', module: 'asm'

        //Was getting this warning, so decided to ignore this version included by WireMock.
        //Warning:Dependency org.json:json:20090211 is ignored as it may be conflicting with the internal version provided by Android.
        //In case of problem, please repackage with jarjar to change the class packages
        exclude group: 'org.json', module: 'json'

        //Jetty was not providing org/eclipse/jetty/http/HttpScheme as expected
        exclude group: 'org.eclipse.jetty', module: 'jetty-http'
    }
    androidTestCompile('org.apache.httpcomponents:httpclient-android:4.3.5.1')
    androidTestCompile('org.eclipse.jetty:jetty-http:9.4.6.v20170531')

Ok but what if you want to use it on Android 5.0- AND Android 5.0+ ?

I can get Wiremock working on Android 5.0, but I still have a failure on :app:transformClassesWithMultidexlistForDebugAndroidTest task on Android 4.3

I also had to compile jetty-http aside, because the class HttpScheme from Jetty was not found on Android 4.3 (but was found on Android 5.0).

 // Wiremock
    androidTestCompile('com.github.tomakehurst:wiremock:2.0.8-beta') {
        //Using Android Version Instead
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'

        //Was getting a classpath conflict for org.objectweb.asm.AnnotationVisitor which is a part of 'net.minidev:asm'
        exclude group: 'asm', module: 'asm'

        //Was getting this warning, so decided to ignore this version included by WireMock.
        //Warning:Dependency org.json:json:20090211 is ignored as it may be conflicting with the internal version provided by Android.
        //In case of problem, please repackage with jarjar to change the class packages
        exclude group: 'org.json', module: 'json'

        //Jetty was not providing org/eclipse/jetty/http/HttpScheme as expected
        exclude group: 'org.eclipse.jetty', module: 'jetty-http'
    }
    androidTestCompile('org.apache.httpcomponents:httpclient-android:4.3.5.1')
    androidTestCompile('org.eclipse.jetty:jetty-http:9.4.6.v20170531')
@tomakehurst

This comment has been minimized.

Show comment
Hide comment
@tomakehurst

tomakehurst Jul 10, 2017

Owner

Closing this as it has become a bit unfocussed.

I'm more than happy to take specific suggestions (and PRs) from the Android community on how to improve the dev experience.

Owner

tomakehurst commented Jul 10, 2017

Closing this as it has become a bit unfocussed.

I'm more than happy to take specific suggestions (and PRs) from the Android community on how to improve the dev experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment