javax.net.ssl.SSLHandshakeException(java.security.cert.CertPathValidatorException: Trust anchor for

我的项目gradle从4.0.0 升级到7.0.4后
项目中需要修改Glide的证书,然后在AndroidManifest.xml中配置对应的OkHttpGlideModule

@GlideModule
public class OkHttpGlideModule extends AppGlideModule {

    private volatile OkHttpClient okHttpClient;

    @Override
    public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
        initOkhttp(context);
        registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(request -> okHttpClient.newCall(request)));
    }

    private void initOkhttp(Context context) {
        //自己处理的逻辑
    }
}

AndroidManifest.xml 代码

 <meta-data
            android:name="com.xxxx.OkHttpGlideModule"
            android:value="AppGlideModule" />

我的Glide是4.0以上版本

implementation "com.github.bumptech.glide:glide:4.14.2"
implementation "com.github.bumptech.glide:okhttp3-integration:4.14.2"
annotationProcessor "com.github.bumptech.glide:compiler:4.14.2"

然后运行就报了下面的错误!!!!

javax.net.ssl.SSLHandshakeException(java.security.cert.CertPathValidatorException: Trust anchor for certification path not found
在这里插入图片描述
遇到上面的问题,2种修改方式

方式一

glide3和glide4有区别
简单改

implementation "com.github.bumptech.glide:glide:4.14.2"
implementation "com.github.bumptech.glide:okhttp3-integration:4.14.2"
kapt "com.github.bumptech.glide:compiler:4.14.2"

然后试了一下,发现可以了

#方式二
就是继承AppGlideModule,需要修改一下
改成继承:com.bumptech.glide.integration.okhttp3.OkHttpGlideModule
把上面的代码修改一下如下

@GlideModule
public class OkHttpGlideModule extends com.bumptech.glide.integration.okhttp3.OkHttpGlideModule{
}

然后
AndroidManifest.xml 代码

 <meta-data
            android:name="com.xxxx.OkHttpGlideModule"
            android:value="GlideModule" />

然后再试一下也可以

具体原因下次再来补充,是跟代码发现的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值