Using Apache HttpClient with Android SDK 23. NoSuchMethod
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
cV2
Updated on June 05, 2022Comments
-
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 over 8 yearsPost your gradle.app where you put the comile
-
Derek Fung over 8 yearsit is starting to duplicate, please kindly search android M httpclient legacy
-
TejaDroid over 8 years@ Revanth Rev and cV2, please check the following link where the solution of your question. stackoverflow.com/questions/32340629/…
-
-
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 over 8 years@CommonsWare sorry English is not my native language, I edited my statement. Thank you.
-
cV2 over 8 yearsthis problem is not related, as i described… the google bug report was rated as "medium && defect…" so … there's an issue as described…
-
JamesDeHart over 8 yearsYou can also add useLibrary 'org.apache.http.legacy' see this post --> stackoverflow.com/questions/32153318/…
-
Chris - Jr over 7 yearsAnother powerful library is Volley, which is in many cases an easier and faster library to use. And it does support HTTPS (SSL)