如何在库模块中使用GlideApp生成的API?

6

构建库模块。在使用该库模块的示例应用程序中,它具有:

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

在库模块中具有以下特点:

@GlideModule
public final class LibGlideModule extends LibraryGlideModule {
}

在库模块中,它使用了由GlideApp生成的API。

fun ImageView.loadImg(imageUrl: String) {
var requestOptions : RequestOptions  = RequestOptions()
requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL)
if (!TextUtils.isEmpty(imageUrl)) {
    GlideApp.with(this.context)
            .setDefaultRequestOptions(requestOptions)
            .load(imageUrl)
            .into(this)
}

但是由于这是库模块,无法依赖应用程序模块,因此它无法编译。

如何在库模块中使用GlideApp生成的API?

参考 - https://bumptech.github.io/glide/doc/configuration.html

1个回答

0

只需添加

annotationProcessor com.github.bumptech.glide:compiler:4.8.0

在您的模块gradle文件中添加依赖项,然后同步项目并进行清理和重建。

如果您的模块使用Kotlin,请将"annotationProcessor"更改为"kapt"。

如果您有其他模块依赖项,请注意确保您使用正确的GlideApp对象。可能其他模块有自己的GlideApp对象。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接