简体   繁体   English

Android 滑翔没有在 Android 4.X 中加载图片

[英]Android glide not loading pictures in Android 4.X

I am using Glide v4.11 to load pictures from the web, everything work fine in android 5.0 or higher but in android 4.X pictures do not load.我正在使用 Glide v4.11 从 web 加载图片,在 android 5.0 或更高版本中一切正常,但在 android 4.X 图片不加载。

Here is my code:这是我的代码:

 RequestOptions options = new RequestOptions()
                    .placeholder(android.R.drawable.progress_horizontal)
                    .error(android.R.drawable.presence_offline)
                    .diskCacheStrategy(DiskCacheStrategy.ALL);

   Glide.with(context)
                    .load(data.getImage_url())
                    .apply(options)
                    .into(holder.thumbnail);

and here is the LogCat on Android 4.4:这是 Android 4.4 上的 LogCat:

W/Glide: Load failed for https://www.gradientapi.xyz/generate/w/1000/h/500 with size [188x263]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
    There was 1 cause:
    javax.net.ssl.SSLHandshakeException(javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb85422a0: Failure in SSL library, usually a protocol error
    error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:766 0xa744e990:0x00000000))
     call GlideException#logRootCauses(String) for more detail
      Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE
    There was 1 cause:
    javax.net.ssl.SSLHandshakeException(javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb85422a0: Failure in SSL library, usually a protocol error
    error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:766 0xa744e990:0x00000000))
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
    There was 1 cause:
    javax.net.ssl.SSLHandshakeException(javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb85422a0: Failure in SSL library, usually a protocol error
    error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:766 0xa744e990:0x00000000))
     call GlideException#logRootCauses(String) for more detail
          Cause (1 of 1): class javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb85422a0: Failure in SSL library, usually a protocol error
    error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:766 0xa744e990:0x00000000)

I searched over web and i found that Android 4.4 only support TLS 1.0.我搜索了 web,发现 Android 4.4 仅支持 TLS 1.0。

It may be the issue?这可能是问题? and if yes is there any solutions?如果是,有什么解决方案吗?

It's a handshake exception.这是握手异常。 On devices older than Android 5.0 TLSv1.1 and TLSv1.2 protocols are not enabled by default and that's why this exception occurs.在早于Android 5.0的设备上, TLSv1.1TLSv1.2协议默认未启用,这就是发生此异常的原因。

You can try this inside your Application's class onCreate method:您可以在应用程序的 class onCreate 方法中尝试此操作:

if (Build.VERSION.SDK_INT == 19) {
        try {
            ProviderInstaller.installIfNeeded(this);
        } catch (Exception ignored) {
        }
    }

Also, You can check this github issue for better solutions.此外,您可以查看此 github 问题以获得更好的解决方案。

I ran into this problem on API 30. It was weird, I was using Retrofit with okhttp just fine to access other things on the same server, but when I tried to use Glide to load an image, I got the dreaded:我在 API 30 上遇到了这个问题。这很奇怪,我使用带有 okhttp 的 Retrofit 可以很好地访问同一服务器上的其他内容,但是当我尝试使用 Glide 加载图像时,我得到了可怕的:

SSLProtocolException: Read error: ssl=0xe78f6a18: Failure in SSL library, usually a protocol error

I saw various posts about much older Android versions having problems with TLS1.2 but that wasn't the issue.我看到了各种关于更旧的 Android 版本存在 TLS1.2 问题的帖子,但这不是问题。 It seems like Glide has a dependency on an older version of OKHttp and that was the problem.看起来 Glide 依赖于旧版本的 OKHttp,这就是问题所在。 Or something like that, not exactly sure, but I did fix it with this in my gradle file:或者类似的东西,不完全确定,但我确实在我的 gradle 文件中修复了它:

implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.12.0'

It seems like the okhttp3-integration is what fixes it.似乎okhttp3-integration可以修复它。 I'm posting this here for anyone else who gets stumped by this and does some searches.我在这里为其他对此感到困惑并进行一些搜索的人发布此内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM