問題一: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)