18

In short my problem is that I can't use GlideApp (generated API) in an activity written in Kotlin.

Interesting enough that Android Studio sees the reference, i can open the generated GlideApp, there is code completion, but when I try to build it, then it fails with

"Unresolved reference: GlideApp"

The glide module was implemented in java since most of the apps code is written in java.

Any idea?

2
  • you should show your code.. Commented Feb 9, 2018 at 13:54
  • It is a simple GlideApp.with call with no error in Android Studio, just when I build the code Commented Feb 9, 2018 at 13:59

7 Answers 7

34

Are using kapt instead of annotationprocessor in gradle file? V4 Generated API support Kotlin

Sign up to request clarification or add additional context in comments.

3 Comments

No because the GlideModule implementation is in java. I understood if that is the case I need to use the java annotation processor
Soo Turns out I NEED to use kapt and it's not an option. Maybe I did not understand the documentation correctly. So if I use kapt for annotation processing even if the GlideModule is implemented in java it seems to work.
Yes. If your project contains Java classes, kapt will also take care of them.
24

For those like me who had used kapt as suggested by karandeep but still had the problem - you have to create an AppGlideModule implementation:

// AppGlideModule.kt import com.bumptech.glide.annotation.GlideModule import com.bumptech.glide.module.AppGlideModule @GlideModule class AppGlideModule : AppGlideModule() 

After rebuilding the project GlideApp can be imported (generated code).

More at this medium post

2 Comments

where do you add those lines?
@johnrao07 those lines typically go into a Dagger2 module file, e.g MyModule.kt. If you want to brush up on Dagger2 modules/components, here's an article that might help: distillery.com/blog/…
21

whoever still facing issue after extending AppGlideModule and adding

kapt 'com.github.bumptech.glide:compiler:4.8.0'

then don't forget to include

apply plugin: 'kotlin-kapt'

on top in app or module build.gradle

Comments

8

You could use Glide instead of GlideApp.

Glide.with(context) .load(image) .apply(RequestOptions().placeholder(R.drawable.image_placeholder)) .into(imageView); 

1 Comment

If you added @GlidedModule, you need to use GlideApp instead of Glide. So this answer is not good for all cases
7

To add Glide app you need to add:

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

Then you can use

Glide.with(..)

That code uses default Glide. If you want to have customized Glide, you will need to add

for kotlin:

kapt 'com.github.bumptech.glide:annotations:4.9.0' 

or for java:

annotationProcessor 'com.github.bumptech.glide:annotations:4.9.0' 

Once when you Sync the project, you need to add Glide module class in your project:

@GlideModule public class CustomGlideModule extends AppGlideModule { @Override public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) { //register some components } } 

Once when you rebuild the project, new class GlideApp will be autogenerated. You can now use Glide with the following code:

GlideApp.with(..)

2 Comments

kapt 'com.github.bumptech.glide:annotations:4.9.0' solved the problem for me
adding the implementation of the direct github repo did it for me. implementation 'com.github.bumptech.glide:glide:4.8.0'
-3

Okay I also had the but after just importing glide it worked import com.bumptech.glide.glide

Comments

-3

Use Glide instead of GlideApp.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.