升级Glide4.x的问题汇总

问题一:Failed to find GeneratedAppGlideModule. You should include an annotationProcessor c

错误信息

W/Glide:
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

原因是:annotationProcessor ‘com.github.bumptech.glide:compiler:4.9.1’,这个依赖只在 glid封装库 中依赖,没有在主工程依赖。

因为我的glide是一个自己的封装库,封装库内有依赖annotationProcessor ‘com.github.bumptech.glide:compiler:4.9.0’,但主工程却没依赖,导致主工程中不能使用注解@GlideModule,这样就MyAppGlideModule没生效了,这样也导致LibraryGlideModule的所有子类无效。

@GlideModule
public class MyAppGlideModule extends AppGlideModule {
    @Override
    public boolean isManifestParsingEnabled() {
        return false;
    }
}

解决方法:主工程也依赖annotationProcessor 'com.github.bumptech.glide:compiler:4.9.1’即可

参考:
关于glide4.7.1使用找不到GlideApp的问题

问题二:透明背景的gif,显示黑色背景

透明背景的动图
问题:这张透明背景的Gif动图,使用Glide加载后,本该透明的地方变为黑色了。
原因:在配置RequestOptions的图片格式时, 我使用了format方法设置为DecodeFormat.PREFER_RGB_565。

RequestOptions options = new RequestOptions()
                .format(DecodeFormat.PREFER_RGB_565)

其中这个方法实现是:同时配置bitmap和Gif的格式。Gif图配置PREFER_RGB_565 透明底就会变黑底(因为PREFER_RGB_565没有透明通道)。源码如下

  public T format(@NonNull DecodeFormat format) {
    Preconditions.checkNotNull(format);
    return set(Downsampler.DECODE_FORMAT, format)
        .set(GifOptions.DECODE_FORMAT, format);
  }

解决方法:单独配置gif即可

        RequestOptions options = new RequestOptions()
                .format(DecodeFormat.PREFER_RGB_565)
                .set(GifOptions.DECODE_FORMAT,DecodeFormat.DEFAULT)

ok

猜你喜欢

转载自blog.csdn.net/hfy8971613/article/details/105970792