我挣扎了将近1天,但找到了解决方案,如果您使用ssl认证的链接,如https,那么您需要添加两个glide依赖项,所以您必须添加此项
implementation 'com.github.bumptech.glide:annotations:4.5.0'
kapt 'com.github.bumptech.glide:compiler:4.5.0'
我正在使用kotlin这就是我添加的原因
卡普特
您可以使用
注释处理器
之后,您需要在项目中创建GlideModule,下面是
滑动V4
@GlideModule
public class MyGlideModule extends AppGlideModule {
@Override
public void applyOptions(Context context, GlideBuilder builder) {
super.applyOptions(context, builder);
}
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
OkHttpClient okHttpClient= UnsafeOkHttpClient.getUnsafeOkHttpClient();
registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(okHttpClient));
}
}
这里我们绕过了ssl,所以这里是
UnsafeOkHttpClient
班
public class UnsafeOkHttpClient {
public static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}
}
};
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
OkHttpClient okHttpClient = builder.build();
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
之后你需要再上两节课
OkHttpUrlLoader和OkHttpStreamFetcher
您可以从复制过去
Glide Link
在我不知道的最后一步之后,这就是为什么需要一天,所以你需要
构建项目
而Glide将生成
GlideApp
类,所以您需要使用
GlideApp类显示图像HTTPS
像这样:
GlideApp.with(context).load(url).apply(RequestOptions.circleCropTransform()).into(imageView)
我认为这对其他遭受这类问题的人来说是非常有帮助的。
保留代码:)