question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

2.1.4-rc3 - Not Working on Android

See original GitHub issue

Client logs:

java.lang.NoSuchMethodError: No direct method <init>(Ljava/lang/String;Lorg/apache/http/entity/ContentType;)V in class Lorg/apache/http/entity/StringEntity; or its super classes (declaration of 'org.apache.http.entity.StringEntity' 

Location of this issue: https://github.com/tomakehurst/wiremock/blob/2.0-beta/src/main/java/com/github/tomakehurst/wiremock/client/HttpAdminClient.java

Line 232:

private String postJsonAssertOkAndReturnBody(String url, String json, int expectedStatus) {
        ...
            StringEntity stringEntity = new StringEntity(json, APPLICATION_JSON);
            post.setEntity(stringEntity);
       ...
}

That StringEntity constructor is not supported on the Apache HTTP Client on Android. Please refer to a previous PR which fixed this to allow support on Android - https://github.com/tomakehurst/wiremock/pull/330/files

Usable on Android:

StringEntity stringEntity = new StringEntity(json);
stringEntity.setContentType(APPLICATION_JSON.getMimeType());
post.setEntity(stringEntity);

This should be updated and documented on why this method signature is used. It looks like this slipped back in as it’s the more concise way to write it. Also, if there are any other usages of this constructor, those should be updated to use this as well.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
tomakehurstcommented, Jul 8, 2016

Ah good, glad it works for you too.

I got it to work by switching to a constructor that took the charset as a String. It is deprecated in the current version of HTTPClient, but still present so I guess it had been around since since the 4.0 version Android provides by default.

0reactions
handstandsamcommented, Jul 9, 2016

Thanks for the explanation, sounds great! I updated my examples project (https://github.com/handstandsam/AndroidHttpMockingExamples) to use 2.1.5-rc4 and it’s working great. I’m closing this as it’s now working 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - gradle - iTecNote
and started getting this error. I tried to clean and rebuild the project but it didn't work. Reverting back to alpha05 version is...
Read more >
Nook HD, HD+ Android Development | Page 2 - XDA Forums
Android development for the Nook HD, HD+.
Read more >
Top 5 Ways to Fix 'Your Device Isn't Compatible with This ...
1. Update Android OS. It's the first thing you should do when you face the 'your device isn't compatible with this version' error...
Read more >
Changelog - NoScript: block scripts and own your browser!
The NoScript Security Suite is a free extensions for Firefox, Chrome and other browsers, preemptively blocks malicious scripts and allows JavaScript and ...
Read more >
3.4 Milestone - GitHub
LineEdit on Android with Hacker's Keyboard ignores or behaves weird on arrow ... "Audio Mic Record Demo" not working on Godot 3.4 archived ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found