Unable to Resolve GlideApp in Glide 4.1.1

Viewed 5458

After Going Through tons of forums about same issue, I still not been able to resolve the GlideApp error. It says it cannot be resolved. Here is the screenshot:

enter image description here

Here is the java class to use details from above

enter image description here

My build.gradle file already contains:

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

Both and also I have class with below code:

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

@GlideModule
public final class CustomAppGlideModule extends AppGlideModule {
}

And I'm using this to to request for:

When I use Glide.with Then it Error says

enter image description here

But still it doesn't solve the problem.

3 Answers

Try 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;
  }
}

Read AppGlideModule

FYI

Your loadImage method will be

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);
    }

Then

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

Try this

Import Glide by adding this in gradle

compile 'com.github.bumptech.glide:glide:3.8.0'

Then use this code

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);

Seems like great discussion going on. Don't worry. I have solution.

Follow the steps:

Add dependency as follow (I used latest version)

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

Create package (as I always used structured code) myglide and copy/paste following class:

@GlideModule
public class SampleGlideModule extends AppGlideModule {
    @Override
    public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
        super.applyOptions(context, builder);
    }
}

Now you can press CTRL+F9 OR you can click on Make Project option in Build menu. It will generate one file automatically (You can see by pressing CTRL and hover on ClassName in File.)

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

Now you can use GlideApp class very easily.

Feel free to contact me if you get any error.

Hope it will helps you. I love Glide as always. <3

Related