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?

Alex
  • 3,382
  • 2
  • 32
  • 41

7 Answers7

34

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

karandeep singh
  • 2,294
  • 1
  • 15
  • 22
  • No because the GlideModule implementation is in java. I understood if that is the case I need to use the java annotation processor – Alex Feb 09 '18 at 14:04
  • 2
    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. – Alex Feb 09 '18 at 15:06
  • 1
    Yes. If your project contains Java classes, kapt will also take care of them. – karandeep singh Feb 09 '18 at 15:08
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

kip2
  • 6,473
  • 4
  • 55
  • 72
  • where do you add those lines? – johnrao07 Oct 10 '20 at 15:38
  • 1
    @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: https://distillery.com/blog/dagger-2-how-to-understand-and-use-components-and-modules/ – kip2 Oct 11 '20 at 19:52
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

dastan
  • 892
  • 10
  • 17
8

You could use Glide instead of GlideApp.

Glide.with(context)
            .load(image)
            .apply(RequestOptions().placeholder(R.drawable.image_placeholder))
            .into(imageView);
Ivo Stoyanov
  • 16,256
  • 8
  • 62
  • 65
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(..)

Mladen Rakonjac
  • 9,562
  • 7
  • 42
  • 55
  • `kapt 'com.github.bumptech.glide:annotations:4.9.0'` solved the problem for me – Andrew Oct 01 '20 at 11:12
  • adding the implementation of the direct github repo did it for me. implementation 'com.github.bumptech.glide:glide:4.8.0' – NMukama Jul 25 '21 at 22:27
-3

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

Nz Mumbere
  • 19
  • 1
  • 5
-3

Use Glide instead of GlideApp.