将 Apache HttpClient 与 Android SDK 23 一起使用. NoSuchMethod [英] Using Apache HttpClient with Android SDK 23. NoSuchMethod

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

问题描述

已经创建了一个bugticket 在谷歌为此.可能有人有任何想法吗?

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

mCloseableHttpClient = HttpClientBuilder.create().setDefaultRequestConfig(defaultRequestConfig).setUserAgent(userAgent).建造();

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

java.lang.NoSuchFieldError:没有 Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier 类型的静态字段 INSTANCE;在类 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变更

您可以使用 HttpURLConnection 类代替.

根据官方指南<块引用>

此 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

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

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