• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier;

武飞扬头像
崔星星
帮助1

问题背景:

由于使用了宜搭平台作为后台数据存储的地方,而调用宜搭的接口要接入其sdk。但是其xxpt.gateway.shared.client-1.1.4.aar包使用了HttpClient来实现网络访问的,但是在android9时HttpClient被完全移除了,但是这个类还在sdk中而且还基本内容都被删除了:


package org.apache.http.conn.ssl;

/**
 * The ALLOW_ALL HostnameVerifier essentially turns hostname verification
 * off. This implementation is a no-op, and never throws the SSLException.
 * 
 * @author Julius Davies
 *
 * @deprecated Please use {@link java.net.URL#openConnection} instead.
 *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
 *     for further details.
 */
@Deprecated
public class AllowAllHostnameVerifier extends AbstractVerifier {

    public final void verify(
            final String host, 
            final String[] cns,
            final String[] subjectAlts) {
        // Allow everything - so never blowup.
    }

    @Override
    public final String toString() { 
        return "ALLOW_ALL"; 
    }
    
}

学新通

普通的HttpClient中的AllowAllHostnameVerifier内容:


package org.apache.http.conn.ssl;

import org.apache.http.annotation.Immutable;

/** @deprecated */
@Deprecated
@Immutable
public class AllowAllHostnameVerifier extends AbstractVerifier {
	//可以知道虽然类也被置为过期的,但INSTANCE静态常量还是在的;
    public static final AllowAllHostnameVerifier INSTANCE = new AllowAllHostnameVerifier();

    public AllowAllHostnameVerifier() {
    }

    public final void verify(String host, String[] cns, String[] subjectAlts) {
    }

    public final String toString() {
        return "ALLOW_ALL";
    }
}
学新通

这就有问题了,当xxpt.gateway.shared.client调用AllowAllHostnameVerifier这个文件时访问里边的属性时会访问到AndroidSdk中的这个类AllowAllHostnameVerifier,但是其中的属性已经被删除了,因此就会报No static field INSTANCE这个错误的。

解决方法:

  1. 引入了cz.msebera.android:httpclient:4.5.8这个库代替HttpClient(是类都改了路径,防止xxpt包使用的为正常功能的那个类);
  2. 复制出xxpt中的所有类:学新通

修改其中使用org.apache.http路径的文件为cz.msebera.android.httpclient路径下的类:
学新通

因此app正常了(看着也能把网络请求替换为UrlConnection或okhttp,不过还没深入研究,后期在进行更新)。

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgbfjfa
系列文章
更多 icon
同类精品
更多 icon
继续加载