Android 滑行 "Cannot Resolve Method 'with' in GlideApp"
Android Glide "Cannot Resolve Method 'with' in GlideApp"
我已经阅读了很多关于此的其他帖子,并且我已经阅读了 Bumptech 上的解释。但是我还是不满意。我有以下代码:
if (image != null) {
GlideApp
.with(this)
.load(imageUrl)
.centerCrop()
.transition(withCrossFade())
.into(eventImageView);
}
其中 returns 上面的错误:无法在 'GlideApp'.
中解决方法 'with'
我按照这个问题的第一个答案:
...但它似乎并没有改变任何东西:
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
@GlideModule
public class GlideApp extends AppGlideModule {
}
最后是我的应用程序 build.gradle:
implementation ("com.github.bumptech.glide:glide:4.11.0") {
exclude group: "com.android.support"
}
annotationProcessor 'androidx.annotation:annotation:1.1.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation ("com.github.bumptech.glide:glide:4.11.0@aar") {
transitive = true
}
不明白为什么Glide突然变得这么复杂...
图像视图是否在片段内?如果是,则将其更改为
Glide.with(getContext()).load(imageUrl).centerCrop().transition(withCrossFade()).into(eventImageView);
根据最新的 instructions,您实际上不需要执行问题 link 中的任何内容。您只需正常使用“Glide”,而不必使用“GLideApp”。
repositories {
google()
jcenter()
}
dependencies {
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}
看起来您也不需要设置自定义 class 或类似的东西。
所以我恢复到我的旧代码:
Glide
.with(this)
.load(imageUrl)
.centerCrop()
.transition(withCrossFade())
.into(eventImageView);
}
我发现当我遇到这个错误的时候,99%的情况是在别的地方构建失败,所以没有生成GlideApp。但是Androidstudio并不总是报原来的错误。这可能会非常令人沮丧。
帮助我找出问题根源的是代码检查(分析-> 检查代码),然后修复所有其他错误。也 gradlew 与 --stacktrace 和 --scan
使 cache/restart 失效会有所帮助,尤其是在进行一些更改之后。
如果您使用 Room,请特别注意 Daos。 Android工作室不会报一些错误。
尝试将此添加到您的 build.gradle:
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
我已经阅读了很多关于此的其他帖子,并且我已经阅读了 Bumptech 上的解释。但是我还是不满意。我有以下代码:
if (image != null) {
GlideApp
.with(this)
.load(imageUrl)
.centerCrop()
.transition(withCrossFade())
.into(eventImageView);
}
其中 returns 上面的错误:无法在 'GlideApp'.
中解决方法 'with'我按照这个问题的第一个答案:
...但它似乎并没有改变任何东西:
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
@GlideModule
public class GlideApp extends AppGlideModule {
}
最后是我的应用程序 build.gradle:
implementation ("com.github.bumptech.glide:glide:4.11.0") {
exclude group: "com.android.support"
}
annotationProcessor 'androidx.annotation:annotation:1.1.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation ("com.github.bumptech.glide:glide:4.11.0@aar") {
transitive = true
}
不明白为什么Glide突然变得这么复杂...
图像视图是否在片段内?如果是,则将其更改为
Glide.with(getContext()).load(imageUrl).centerCrop().transition(withCrossFade()).into(eventImageView);
根据最新的 instructions,您实际上不需要执行问题 link 中的任何内容。您只需正常使用“Glide”,而不必使用“GLideApp”。
repositories {
google()
jcenter()
}
dependencies {
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}
看起来您也不需要设置自定义 class 或类似的东西。
所以我恢复到我的旧代码:
Glide
.with(this)
.load(imageUrl)
.centerCrop()
.transition(withCrossFade())
.into(eventImageView);
}
我发现当我遇到这个错误的时候,99%的情况是在别的地方构建失败,所以没有生成GlideApp。但是Androidstudio并不总是报原来的错误。这可能会非常令人沮丧。
帮助我找出问题根源的是代码检查(分析-> 检查代码),然后修复所有其他错误。也 gradlew 与 --stacktrace 和 --scan
使 cache/restart 失效会有所帮助,尤其是在进行一些更改之后。
如果您使用 Room,请特别注意 Daos。 Android工作室不会报一些错误。
尝试将此添加到您的 build.gradle:
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'