3

Already created a bugticket at Google for this. Possibly anyone has any ideas?

I wanted to use a normal HTTPClient (CloseableHttpClient) within Apache Library,

mCloseableHttpClient = HttpClientBuilder.create()
                .setDefaultRequestConfig(defaultRequestConfig)
                .setUserAgent(userAgent)
                .build();

and the Application always directly crashes with:

java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/ext.jar)
            at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
            at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:912)

starting at API Level 22 (same for API Level 23).

The problem is: The class within the Android SDK doesn't have INSTANCE field declared.

3
  • Post your gradle.app where you put the comile Commented Aug 31, 2015 at 13:55
  • it is starting to duplicate, please kindly search android M httpclient legacy Commented Aug 31, 2015 at 14:02
  • @ Revanth Rev and cV2, please check the following link where the solution of your question. stackoverflow.com/questions/32340629/… Commented Sep 21, 2015 at 6:43

2 Answers 2

4

The following class has been removed as of API level 22

org.apache.http.conn.ssl.AllowAllHostnameVerifier

You can see the removed classes in the official api changes

You can use HttpURLConnection class instead.

According to official guide

This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption

** EDIT **

According to CommonsWare's comment below, there are also other 3rd party options including OkHttp or Apache's separate HttpClient library for Android

Sign up to request clarification or add additional context in comments.

5 Comments

"You have to use HttpURLConnection class instead" -- no. While HttpClient itself is removed, and HttpURLConnection is an option, there are other options, such as OkHttp or Apache's separate HttpClient library for Android.
@CommonsWare sorry English is not my native language, I edited my statement. Thank you.
this problem is not related, as i described… the google bug report was rated as "medium && defect…" so … there's an issue as described…
You can also add useLibrary 'org.apache.http.legacy' see this post --> stackoverflow.com/questions/32153318/…
Another powerful library is Volley, which is in many cases an easier and faster library to use. And it does support HTTPS (SSL)
-1

Is a problem of a library version try with this versions

implementation 'org.apache.httpcomponents:httpclient:4.5.3'
    api 'org.apache.httpcomponents:httpcore:4.4.6'
    api 'org.apache.httpcomponents:httpmime:4.3.6'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.