Android Glide遇到的問題總結

Android Glide使用遇到的問題

Android Glide中的註解不兼容AndroidX

今天在進行Glide二次封裝的時候,發現Glide中的註解不兼容androidX。查找了一些資料,最後總結一下:

參考資料:https://github.com/bumptech/glide/issues/3185

問題描述:當我們進行Glide框架引用的時候,我們通常是按照如下方式:

    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    implementation 'com.github.bumptech.glide:okhttp3-integration:4.9.0'

我們在使用的時候回發現提示是這樣的:
android.support.annotation.CheckResultandroid.support.annotation.NonNull 提示是不存在的

根據上面GitHub中獲取到的知識點總結方法如下的:

    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    implementation 'com.github.bumptech.glide:okhttp3-integration:4.9.0'
    implementation 'com.android.support:support-annotations:28.0.0'
    annotationProcessor 'com.android.support:support-annotations:28.0.0'

通過如上方法進行包的引用即可解決;

Android Glide中GlideApp無法生成問題解決

如若要使用GlideApp需要做的是:
  1. 自定義一個類extends AppGlideModule
  2. 爲這個類加入註解@GlideModule
/**
 * @author by lvzhongdi on 2019/7/24.
 */
@GlideModule
public class ProgressAppGlideModule extends AppGlideModule {
    @Override
    public void registerComponents(@NonNull Context context, @NonNull                               Glide glide, @NonNull Registry registry) {
        super.registerComponents(context, glide, registry);
       
    }
}

完成如上操作後:Clear 一下工程,然後再 Build 一下即可生成 GlideApp

注意 使用GlideApp這個類,SDK build版本必須爲>=27

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章