Using Apache HttpClient with Android SDK 23. NoSuchMethod

16,813

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

Share:
16,813
cV2
Author by

cV2

Updated on June 05, 2022

Comments

  • cV2
    cV2 almost 2 years

    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.

    • Skizo-ozᴉʞS
      Skizo-ozᴉʞS over 8 years
      Post your gradle.app where you put the comile
    • Derek Fung
      Derek Fung over 8 years
      it is starting to duplicate, please kindly search android M httpclient legacy
    • TejaDroid
      TejaDroid over 8 years
      @ Revanth Rev and cV2, please check the following link where the solution of your question. stackoverflow.com/questions/32340629/…
  • CommonsWare
    CommonsWare over 8 years
    "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.
  • Sharp Edge
    Sharp Edge over 8 years
    @CommonsWare sorry English is not my native language, I edited my statement. Thank you.
  • cV2
    cV2 over 8 years
    this problem is not related, as i described… the google bug report was rated as "medium && defect…" so … there's an issue as described…
  • JamesDeHart
    JamesDeHart over 8 years
    You can also add useLibrary 'org.apache.http.legacy' see this post --> stackoverflow.com/questions/32153318/…
  • Chris - Jr
    Chris - Jr over 7 years
    Another powerful library is Volley, which is in many cases an easier and faster library to use. And it does support HTTPS (SSL)