Glide无法加载图片。

huangapple go评论52阅读模式
英文:

Glide does not load images

问题

我的代码是标准的:

options = options.transforms(CenterCrop(), RoundedCorners(3.px))
            Glide.with(itemView.context).load(flower.profilePicture.prefixHttp())
                .apply(options)
                .transition(
                    DrawableTransitionOptions.withCrossFade()
                ).into(flowerImage)

我进行了调试并获得了以下信息:

flower.profilePicture.prefixHttp() = http://flowrspot.s3.amazonaws.com/flowers/profile_pictures/000/000/007/medium/L_00010.jpg?1527514226

这是完全正常的。我尝试了多个依赖项:

//    implementation 'com.github.bumptech.glide:glide:4.8.0';
//    kapt 'com.github.bumptech.glide:compiler:4.8.0';

implementation 'com.github.bumptech.glide:glide:4.14.2';
annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2';

但它仍然无法加载。在我的Logcat中,我收到一些警告/错误信息:

"Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored"

"Load failed for [http://flowrspot.s3.amazonaws.com/flowers/profile_pictures/000/000/007/medium/L_00010.jpg?1527514226] with dimensions [420x525]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 root cause:
com.bumptech.glide.load.HttpException(Failed to connect or obtain data, status code: -1)
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 root cause:
com.bumptech.glide.load.HttpException(Failed to connect or obtain data, status code: -1)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
There was 1 root cause:
com.bumptech.glide.load.HttpException(Failed to connect or obtain data, status code: -1)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.HttpException: Failed to connect or obtain data, status code: -1"

这里发生了什么情况。从未见过Glide表现得像这样...

英文:

My code is standard:

options = options.transforms(CenterCrop(), RoundedCorners(3.px))
                Glide.with(itemView.context).load(flower.profilePicture.prefixHttp())
                    .apply(options)
                    .transition(
                        DrawableTransitionOptions.withCrossFade()
                    ).into(flowerImage)

I debugged and get

flower.profilePicture.prefixHttp() = http://flowrspot.s3.amazonaws.com/flowers/profile_pictures/000/000/007/medium/L_00010.jpg?1527514226

which is totally fine. I tried with multiple dependencies:

//    implementation 'com.github.bumptech.glide:glide:4.8.0'
//    kapt 'com.github.bumptech.glide:compiler:4.8.0'

    implementation 'com.github.bumptech.glide:glide:4.14.2'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2'

But it just does not load. In my logcat I get some warnings/errors written:

"Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored"

"Load failed for [http://flowrspot.s3.amazonaws.com/flowers/profile_pictures/000/000/007/medium/L_00010.jpg?1527514226] with dimensions [420x525]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 root cause:
com.bumptech.glide.load.HttpException(Failed to connect or obtain data, status code: -1)
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 root cause:
com.bumptech.glide.load.HttpException(Failed to connect or obtain data, status code: -1)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
There was 1 root cause:
com.bumptech.glide.load.HttpException(Failed to connect or obtain data, status code: -1)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.HttpException: Failed to connect or obtain data, status code: -1"

What is going on here. Never seen glide behave like this...

答案1

得分: 1

通过在Android应用的AndroidManifest.xml文件中将usesCleartextTraffic属性设置为true,允许应用向HTTP(非HTTPS)URL发出网络请求。

因为从Android 9(Pie)开始,默认值usesCleartextTraffic为false(禁用),这意味着应用不被允许向HTTP URL发出网络请求。

英文:

By setting the usesCleartextTraffic attribute to true in your Android app's AndroidManifest.xml file allows the app to make network requests to HTTP (non-HTTPS) URLs.

Because, starting from Android 9 (Pie), the default value of usesCleartextTraffic is false (disabled), which means that apps are not allowed to make network requests to HTTP URLs.

huangapple
  • 本文由 发表于 2023年2月10日 04:21:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75404036.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定