库模块升级到Glide 4,AppGlideModule应该放在哪里

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

在库模块中升级到Glide 4.9.0。

    api "com.github.bumptech.glide:glide:4.9.0"
    api "com.github.bumptech.glide:annotations:4.9.0"
    annotationProcessor "com.github.bumptech.glide:compiler:4.9.0" 

并有一个kotlin延伸

fun ImageView.loadImg(imageUrl: String) {
    // 4.+ code
    var requestOptions : RequestOptions = RequestOptions()
            .placeholder(ColorDrawable(Color.LTGRAY))
            .diskCacheStrategy(DiskCacheStrategy.ALL)

    if (!TextUtils.isEmpty(imageUrl)) {
        Glide.with(context)
                .setDefaultRequestOptions(requestOptions)  // or use .apply(requestOptions) but after the .load()
                .asBitmap()
                .load(imageUrl)
                .into(this)
    }
}


but it crashes

    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)
            at com.common.extentions.ExtensionsKt.loadImg(Extensions.kt:44)

添加后

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

到库模块没有帮助,或者将它添加到托管应用程序只是不起作用,但在将它添加到库模块和托管应用程序后,崩溃消失了。

根据文档https://bumptech.github.io/glide/doc/generatedapi.html,不是它不应该在库模块中定义这个类吗?

谁有相同的经历?

  * For now the API is only generated when a properly annotated AppGlideModule is found.
  * There can only be one AppGlideModule per application.
  * As a result it’s not possible to generate the API for a library without precluding any application
  * that uses the library from using the generated API.
android-glide appglidemodule
1个回答
0
投票

已经解决了,它已经错过了

api "com.github.bumptech.glide:annotations:$versions.glide"

在应用程序方面(不确定为什么在模块中添加单个一个不起作用以及为什么它们都工作,可能在更改后没有做清除/重建?)

© www.soinside.com 2019 - 2024. All rights reserved.