Glide: Glide compiler for AndroidX project partially supports `androidx.annotation` namespace

Created on 5 Jul 2018  路  33Comments  路  Source: bumptech/glide

Currently Glide compiler is partially supporting androidx.annotation namespace, currently the AndroidX project I am building is failing because Glide compiler is still using android.support.annotation.CheckResult and android.support.annotation.NonNull rather than its successors androidx.annotation.NonNull & androidx.annotation.CheckResult.

I have tried with both versions 4.7.1 & 4.8.0-SNAPSHOT

It would be great if the AndroidX annotation namespace is completely supported rather than partially supported.

Basically any occurrence of android.support.annotation should change to androidx.annotation

enhancement

Most helpful comment

implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'androidx.annotation:annotation:1.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

(with

android.enableJetifier=true
android.useAndroidX=true

in gradle.properties)
worked for me

All 33 comments

For now I temporarily added the below so that there is no longer a compilation error:

// TODO remove temporary fix for Glide compiler issue
// Temporary fix begin
implementation 'com.android.support:support-annotations:27.1.1'
annotationProcessor 'com.android.support:support-annotations:27.1.1'
// Temporary fix end

Temporary fix not working for me with android databinding enabled.

@Rajeshr34 Hey there, are you using AndroidX? Please post your error as well

@KevinLeigh Same annotation errors.... also tried to make change and build but its not worked for me. is there any solution for this?

@Rajeshr34
It works fine on my side, please see below the project setup that I am using.

I am using Glide 4.8.0-SNAPSHOT for both annotation processor library and core library. I am using Android Studio IDE 3.3 Canary build Version 2 with Gradle version 4.8, as well as Gradle build tools 3.3.0-alpha02. I would not recommend this setup for a project that is in production that should use only stable versions of libraries. This current setup is only for trying out certain features that are not yet available in stable releases.

@Rajeshr34

Another thing is you should always clean rebuild your project correctly when making major updates.

The reason the temporary fix should work is because android.support.annotation does not exist when you update to use androidx.annotation, and Glide compiler is currently using both namespaces to generate classes. So importing older namespace android.support.annotation will include the missing namespace that no longer exists when using androidx.annotation, so your project should now have both namespaces.

@KevinLeigh Thank You. its working now

implementation 'com.github.bumptech.glide:glide:4.8.0-SNAPSHOT'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0-SNAPSHOT'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.8.0-SNAPSHOT@aar'
implementation "com.android.support:support-annotations:28.0.0-alpha3"
annotationProcessor 'com.android.support:support-annotations:28.0.0-alpha3'

@Rajeshr34 All good, glad it is working on your side.

Hi,
The solution sounds good, but when will be the 4.8.0-SNAPSHOT version available?

@kerjani 4.8.0-SNAPSHOT is out

allprojects {
    repositories {
        google()
        jcenter()

        /*glide snapshot repo*/
        maven {
            name 'glide-snapshot'
            url 'http://oss.sonatype.org/content/repositories/snapshots'
        }

        //Image Gallery
        maven { url "https://jitpack.io" }
    }
}

@Rajeshr34 is it working for you? here it's still using damn android.support.annotation package rather than android.xannotation

4.8.0-SNAPSHOT works for me

I solved this by normally using stable version 4.7.1, and added files Nullable.java and CheckResult.java into my project from Android SDK sources (into correct path android\support\annotation). Then Glide finds its annotation classed, and it works, while my app uses AndroidX.

I can confirm using Glide version 4.8.0 works for me in combination with androidX.
Make sure to activate android.enableJetifier=true in your gradle.properties. In addition, I had to clean the project before I could finally get rid of various build errors and get it to work.
Found the tips here https://github.com/bumptech/glide/issues/3184#issuecomment-404665340 and confirmation on https://github.com/bumptech/glide/issues/3229#issuecomment-414068284

In build.gradle
api 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

In gradle.properties
android.enableJetifier=true
android.useAndroidX=true

But still having compile time error for
Glide.with((androidx.fragment.app.Fragment) fragmentInstance);
Cannot resolve method with androidx.fragment.app.Fragment

@friederikewild
In build.gradle
implementation 'com.github.bumptech.glide:glide:4.8.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
In gradle.properties
android.enableJetifier=true android.useAndroidX=true
but still can't convert "android.support.annotation.CheckResult" and "android.support.annotation.NonNull"

i have to add "com.android.support:support-annotations:28.0.0-alpha3" in gradle锛宭ike this
implementation 'com.github.bumptech.glide:glide:4.8.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0' implementation "com.android.support:support-annotations:28.0.0-alpha3" annotationProcessor 'com.android.support:support-annotations:28.0.0-alpha3'
after add "com.android.support:support-annotations:28.0.0-alpha3" , i can complier and install

implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'androidx.annotation:annotation:1.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

(with

android.enableJetifier=true
android.useAndroidX=true

in gradle.properties)
worked for me

It sounds like this does in fact work, so I'm going to close this issue.

If anyone who has gotten it to work is interested, it would be great to have something on our setup page: http://bumptech.github.io/glide/doc/download-setup.html. There's documentation on contributing to that site here: http://bumptech.github.io/glide/dev/contributing.html#documentation

@HimanshuNarang have you found a fix for this?:

But still having compile time error for
Glide.with((androidx.fragment.app.Fragment) fragmentInstance);
Cannot resolve method with androidx.fragment.app.Fragment

I stopped using androidx. But I think according to @PiN73

implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'androidx.annotation:annotation:1.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

(with

android.enableJetifier=true
android.useAndroidX=true

in gradle.properties)
worked for me

This will work.

@HimanshuNarang Maybe I missed something, but I could not get the generated code to import androidx.fragment.app.Fragment (even using @PiN73's fix). It is the only problem I have yet to fix integrating Glide and AndroidX..

It sounds like this does in fact work, so I'm going to close this issue.

So when can we expect a stable release without the need of extra dependencies like the annotationProcessor? It's almost 2019 now.

@KevinLeigh Thank You. its working now

implementation 'com.github.bumptech.glide:glide:4.8.0-SNAPSHOT'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0-SNAPSHOT'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.8.0-SNAPSHOT@aar'
implementation "com.android.support:support-annotations:28.0.0-alpha3"
annotationProcessor 'com.android.support:support-annotations:28.0.0-alpha3'

Thank you, man. One would not expect this could actually resolve the problem because "support-annotations" was not imported at the very beginning.

I did further test based on @KevinLeigh solution, it turns out that all we need is to add
annotationProcessor 'com.android.support:support-annotations:28.0.0'
which is something that I would not expect.

use annotationProcessor 'androidx.annotation:annotation:1.0.0' can solve this problem

If you are targeting for Android API 28(Pie) and Glide 4.9, then conform to this.

implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'androidx.annotation:annotation:1.1.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

@jmhabuild has the correct answer; so if you are using androidx and Glide 4.9.0, add:
annotationProcessor 'androidx.annotation:annotation:1.1.0'
as he suggests. Worked for me.

Since I can't possibly be the only one who was still having problems generating the API, should this not be added to the docs?

I am getting the same error. Using glide 4.9.0. Any solution?

I can confirm using Glide version 4.8.0 works for me in combination with androidX.
Make sure to activate android.enableJetifier=true in your gradle.properties. In addition, I had to clean the project before I could finally get rid of various build errors and get it to work.
Found the tips here #3184 (comment) and confirmation on #3229 (comment)

A year later and your reply saved me. Thanks a lot!

I am getting the same error. Using glide 4.9.0. Any solution?

Mee too.
There was the content of: build/generated/source/apt/debug/com/dylanvann/fastimage/GlideOptions.java

import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import androidx.annotation.DrawableRes;
import androidx.annotation.FloatRange;

So I end-up with:
https://github.com/DylanVann/react-native-fast-image/blob/master/docs/app-glide-module.md

to solve my issue.

implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'androidx.annotation:annotation:1.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

(with

android.enableJetifier=true
android.useAndroidX=true

in gradle.properties)
worked for me

It works for me

FWIW, the following dependencies are working in my project with Glide 4.9.0 and SDK 28. I recall converting the project to androidx when I was using 4.8.0, then upgraded Glide to 4.9.0.

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'com.google.android.material:material:1.1.0-alpha09'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta03'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.github.bumptech.glide:annotations:4.9.0'
annotationProcessor 'androidx.annotation:annotation:1.1.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.google.code.gson:gson:2.8.5'

I can confirm using Glide version 4.8.0 works for me in combination with androidX.
Make sure to activate android.enableJetifier=true in your gradle.properties. In addition, I had to clean the project before I could finally get rid of various build errors and get it to work.
Found the tips here #3184 (comment) and confirmation on #3229 (comment)
@friederikewild

is clean you mean these steps:

  1. invalidate caches & restart
  2. delete `~./gradle/caches
  3. delete /my_project/.idea & `/my_project/.gradle/
  4. clean & rebuild project

the above steps still doesn't works for me, unless I'm using this step: https://github.com/facebook/facebook-android-sdk/issues/591#issuecomment-610671930 (in my case Glide works with this)

But, the process doesn't succeed that ways, my other libraries also failed to build

Then I've created an SO Question about this migration (for future reader) and "temporary" approach for my problem when migrating to AndroidX

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FooBarBacon picture FooBarBacon  路  3Comments

Morteza-Rastgoo picture Morteza-Rastgoo  路  3Comments

MrFuFuFu picture MrFuFuFu  路  3Comments

Tryking picture Tryking  路  3Comments

kooeasy picture kooeasy  路  3Comments