在 Android SDK 23 中使用 Apache HttpClient.NoSuchMethod [英] Using Apache HttpClient with Android SDK 23. NoSuchMethod

查看:19
本文介绍了在 Android SDK 23 中使用 Apache HttpClient.NoSuchMethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经创建了 bugticket 在谷歌为此.可能有人有什么想法吗?

我想在 Apache 库中使用普通的 HTTPClient (CloseableHttpClient),

mCloseableHttpClient = HttpClientBuilder.create().setDefaultRequestConfig(defaultRequestConfig).setUserAgent(用户代理).建造();

并且应用程序总是直接崩溃:

java.lang.NoSuchFieldError: 没有 Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier 类型的静态字段实例;在 Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier 类中;或其超类('org.apache.http.conn.ssl.AllowAllHostnameVerifier' 的声明出现在/system/framework/ext.jar 中)在 org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)在 org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:912)

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

问题是:Android SDK 中的类没有 INSTANCE 字段声明.

解决方案

自 API 级别 22 起,以下类已被删除

org.apache.http.conn.ssl.AllowAllHostnameVerifier

你可以在官方api changes中看到被移除的类

您可以改用 HttpURLConnection 类.

根据官方指南p><块引用>

此 API 更高效,因为它通过透明压缩和响应缓存减少了网络使用,并将功耗降至最低

** 编辑 **

根据 CommonsWare 下面的评论,还有其他 3rd 方选项,包括 OkHttpApache 独立的 Android HttpClient 库

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.

解决方案

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

这篇关于在 Android SDK 23 中使用 Apache HttpClient.NoSuchMethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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