升级到Glide 4.9.0时如何解决AbstractMethodError

问题描述 投票:0回答:1

这是在库模块中,所以它不应该使用生成的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个回答
0
投票

事实证明,在这个库模块中,它间接依赖于使用Glide3的人,并且拥有Old GlideModule,它不会阻止Glide 4所需的功能。

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

 for (com.bumptech.glide.module.GlideModule module : manifestModules) {
      module.registerComponents(applicationContext, glide, glide.registry);
    }
© www.soinside.com 2019 - 2024. All rights reserved.