结合使用Apache HttpClient和Android SDK23.NoSuchMethod [英] Using Apache HttpClient with Android SDK 23. NoSuchMethod
问题描述
已经创建了 bugticket 一个>在谷歌为此. 可能有人有什么主意吗?
Already created a bugticket at google for this. Possibly anyone has any ideas?
伙计们,我想在Apache库中使用普通的HTTPClient
(CloseableHttpClient),
Hey guys, 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).
问题是:Android SDK中的类没有 INSTANCE 字段已声明.
The Problem is: The class within the Android SDK doesnt have INSTANCE field declared.
推荐答案
从API级别22开始,以下类已被删除
The following class has been removed as of API level 22
org.apache.http.conn.ssl.AllowAllHostnameVerifier
您可以在 api更改中看到删除的类
You can see the removed classes in the official api changes
您可以改用 HttpURLConnection 类
根据官方指南 >
此API效率更高,因为它通过透明压缩和响应缓存减少了网络使用,并最大程度地降低了功耗
This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption
** 编辑 **
根据下面的CommonsWare评论,还有其他第三方选项,包括 OkHttp 或 Apache的Android单独的HttpClient库
According to CommonsWare's comment below, there are also other 3rd party options including OkHttp or Apache's separate HttpClient library for Android
这篇关于结合使用Apache HttpClient和Android SDK23.NoSuchMethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!