结合使用Apache HttpClient和Android SDK23.NoSuchMethod [英] Using Apache HttpClient with Android SDK 23. NoSuchMethod

查看:119
本文介绍了结合使用Apache HttpClient和Android SDK23.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)

开始 22级(对于API级别 23 相同).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆