Glide 4.1.1 无法解析GlideApp

Unable to Resolve GlideApp in Glide 4.1.1

在浏览了大量关于同一问题的论坛后,我仍然无法解决 GlideApp 错误。它说无法解决。这是屏幕截图:

这里是javaclass使用上面的细节

我的 build.gradle 文件已经包含:

  compile 'com.github.bumptech.glide:glide:4.1.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.1.1'

我和我都有 class,代码如下:

import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

@GlideModule
public final class CustomAppGlideModule extends AppGlideModule {
}

我用它来请求:

当我使用Glide.with然后它错误说

但是还是没有解决问题

试试

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

DEMO

@GlideModule
public class FlickrGlideModule extends AppGlideModule {

  @Override
  public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
    super.applyOptions(context, builder);
    builder.setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_ARGB_8888));
  }

  @Override
  public void registerComponents(@NonNull Context context, @NonNull Glide glide,
      @NonNull Registry registry) {
    registry.append(Photo.class, InputStream.class, new FlickrModelLoader.Factory());
  }

  // Disable manifest parsing to avoid adding similar modules twice.
  @Override
  public boolean isManifestParsingEnabled() {
    return false;
  }
}

阅读AppGlideModule

仅供参考

您的loadImage方法将是

public static void loadImage(Context ctx,RequestOptions glideRequests, String url, ImageView imageView) {
        loadImage(ctx,glideRequests, url, imageView, DiskCacheStrategy.ALL);
    }

    public static void loadImage(Context ctx,RequestOptions glideRequests, String url, ImageView imageView, DiskCacheStrategy diskCacheStrategy) {

                 Glide.with(ctx)
                    .applyDefaultRequestOptions(requestOptions.placeholder(R.drawable.ic_stub).error(R.drawable.ic_stub))
                    .asBitmap()
                    .load(url).into(imageView);
    }

然后

ImageUtil.loadImage(context,options,obj.getPhotoUrl(),avatarImageView);

试试这个

通过在 gradle

中添加这个来导入 Glide
compile 'com.github.bumptech.glide:glide:3.8.0'

然后使用这个代码

Glide.with(context)
        .load(url)
        .placeholder(R.drawable.ic_male)
        .error(R.drawable.imagenotfound)
        .listener(new RequestListener<String, GlideDrawable>() {
            @Override
            public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                // log exception
                Log.e("TAG", handle error case", e);
                return false; 
            }

            @Override
            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                 Log.e("TAG", handle success case here", e);
                return false;
            }
        })
        .into(avatarImageView);

似乎正在进行很好的讨论。不用担心。我有办法。

按照以下步骤操作:

如下添加依赖(我用的是最新版本)

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

在 class:

之后创建包(因为我一直使用结构化代码)myglide 和 copy/paste
@GlideModule
public class SampleGlideModule extends AppGlideModule {
    @Override
    public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
        super.applyOptions(context, builder);
    }
}

现在您可以按 CTRL+F9 或者您可以点击 Make Project 中的选项 Build 菜单。 会自动生成一个文件(按住CTRL鼠标悬停在File中的ClassName即可看到)

final class GeneratedAppGlideModuleImpl extends GeneratedAppGlideModule {
  private final SampleGlideModule appGlideModule;
  ....
}

现在您可以非常轻松地使用 GlideApp class。

如果您有任何错误,请随时与我联系。

希望对您有所帮助。我一如既往地爱 Glide。 <3