【问题标题】:How to resolve the AbstractMethodError when upgrade to Glide 4.9.0升级到 Glide 4.9.0 时如何解决 AbstractMethodError
【发布时间】:2019-02-22 21:46:07
【问题描述】:

这是在一个库模块中,所以它不应该使用生成的 API

升级到 Glide 4.9.0

versions.glide = "4.9.0"

implementation "com.github.bumptech.glide:glide:$versions.glide"
kapt "com.github.bumptech.glide:compiler:$versions.glide"
implementation "com.github.bumptech.glide:annotations:$versions.glide"

更新了代码,GlideApp没有地方使用

fun ImageView.loadImg(imageUrl: String) {

// 3.8.0
//    if (!TextUtils.isEmpty(imageUrl)) {
//        Glide.clear(this)
//
//        Glide.with(context).load(imageUrl)
//                .diskCacheStrategy(DiskCacheStrategy.ALL)
//                .placeholder(ColorDrawable(Color.LTGRAY))
//                .into(this)
//    }

///
// 4.+ code
    var requestOptions : RequestOptions = RequestOptions()
        .placeholder(ColorDrawable(Color.LTGRAY))
        .diskCacheStrategy(DiskCacheStrategy.ALL)

    if (!TextUtils.isEmpty(imageUrl)) {
        Glide.with(context)
            .setDefaultRequestOptions(requestOptions)  
            .asBitmap()
            .load(imageUrl)
            .into(this)
    }
}

fun ImageView.clear() {
    Glide.with(this.context).clear(this)
}

Glide.with() 发生崩溃

    java.lang.AbstractMethodError: abstract method "void    com.bumptech.glide.module.RegistersComponents.registerComponents(android.content.Context, com.bumptech.glide.Glide, com.bumptech.glide.Registry)"
    at com.bumptech.glide.Glide.initializeGlide(Glide.java:270)
    at com.bumptech.glide.Glide.initializeGlide(Glide.java:223)
    at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:184)
    at com.bumptech.glide.Glide.get(Glide.java:168)
    at com.bumptech.glide.Glide.getRetriever(Glide.java:689)
    at com.bumptech.glide.Glide.with(Glide.java:716)

如果添加

@GlideModule
class DPAppGlideModule : AppGlideModule() {
    override fun isManifestParsingEnabled(): Boolean {
        return false
    }
}

它会起作用,但由于这是一个库模块,所以它不应该有这个。

AbstractMethodError: abstract method "void com.bumptech.glide.module.RegistersComponents.registerComponents(android.content.Context, com.bumptech.glide.Glide, com.bumptech.glide.Registry)" 的原因可能是什么?

除了 GlideApp 之外的任何东西也应该避免?

【问题讨论】:

    标签: android-glide


    【解决方案1】:

    在这个库模块中,它间接依赖于使用 Glide3 的人,并且拥有旧的 GlideModule,它不执行 Glide 4 所需的功能。

    Glide 4 的 module.registerComponents(applicationContext, glide, glide.registry);取 3 个参数,但 Glide 3 只有两个

     for (com.bumptech.glide.module.GlideModule module : manifestModules) {
          module.registerComponents(applicationContext, glide, glide.registry);
        }
    

    【讨论】:

      猜你喜欢
      • 2015-12-03
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多