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 doesnt have INSTANCE field declared.

peterh
  • 11,875
  • 18
  • 85
  • 108
cV2
  • 5,229
  • 3
  • 43
  • 53

2 Answers2

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

Sharp Edge
  • 4,144
  • 2
  • 27
  • 41
  • "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](http://square.github.io/okhttp/) or [Apache's separate HttpClient library for Android](https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html). – CommonsWare Aug 31 '15 at 14:25
  • @CommonsWare sorry English is not my native language, I edited my statement. Thank you. – Sharp Edge Aug 31 '15 at 14:28
  • this problem is not related, as i described… the google bug report was rated as "medium && defect…" so … there's an issue as described… – cV2 Sep 01 '15 at 21:36
  • You can also add useLibrary 'org.apache.http.legacy' see this post --> http://stackoverflow.com/questions/32153318/httpclient-wont-import-in-android-studio – JamesDeHart Sep 03 '15 at 17:34
  • Another powerful library is [Volley](https://developer.android.com/training/volley/index.html), which is in many cases an easier and faster library to use. And it does support HTTPS (SSL) – Chris - Jr Oct 14 '16 at 14:56
-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'
gureangel
  • 155
  • 1
  • 7