关于在安卓上使用不兼容的Apache Http Api

  最近,碰到一个需要使用Aether包来在安卓App内下载jar的需求,在IDEA上实现了,没有任何问题,但是在安卓上却遇到了异常:

java.lang.NoSuchMethodError:No direct method <init>(Ljavax/net/ssl/SSLSocketFactory;Lorg/apache/http/conn/ssl/X509HostnameVerifier;)V in class Lorg/apache/http/conn/ssl/SSLSocketFactory; or its super classes(declaration of 'org.apache.http.conn.ssl.SSLSocketFactory' appears in /system/framework/framework.jar!classes3.dex)

framework/framework.jar!classes3.dex)

at org.eclipse.aether.transport.http.SslSocketFactory.<init(SslSocketFactory.java:57)

...

   原来是org.eclipse.aether.transport.http.SslSocketFactory的构造方法里面出现问题了,我们顺藤摸瓜看看为啥:

(在Android Studio内,切换到Project工程结构展示,展开External Libraries,进入org.eclipse.aether.transport-http包内查找)

org.eclipse.aether.transport.http.SslSocketFactory文件内容:

final class SslSocketFactory
    extends org.apache.http.conn.ssl.SSLSocketFactory
{
...
    private SslSocketFactory( SSLSocketFactory socketfactory, X509HostnameVerifier hostnameVerifier,
                              String[] cipherSuites, String[] protocols )
    {
        super( socketfactory, hostnameVerifier );

        this.cipherSuites = cipherSuites;
        this.protocols = protocols;
    }
...
}

  在AS内可以看到这里已经显示报错了:

 同理,进入父类中看看为什么:

 发现原来根本没有这个构造方法,我便查了相关的资料:

这里写图片描述

而,这个需求无法使用legacy包解决, 我只好另外想办法。

JarFilter:Jar包文件替换插件

在无奈中,发现了[Github]JarFilter<

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值