Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glide compiler for AndroidX project partially supports androidx.annotation namespace #3185

Closed
KevinLeigh opened this issue Jul 5, 2018 · 33 comments

Comments

@KevinLeigh
Copy link

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

@KevinLeigh KevinLeigh changed the title Glide compiler for AndroidX project partially supports androidx.annotation Glide compiler for AndroidX project partially supports androidx.annotation namespace Jul 5, 2018
@KevinLeigh
Copy link
Author

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

@Rajeshr34
Copy link

Temporary fix not working for me with android databinding enabled.

@KevinLeigh
Copy link
Author

KevinLeigh commented Jul 6, 2018

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

@Rajeshr34
Copy link

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

@KevinLeigh
Copy link
Author

KevinLeigh commented Jul 6, 2018

@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.

@KevinLeigh
Copy link
Author

@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.

@Rajeshr34
Copy link

@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'

@KevinLeigh
Copy link
Author

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

@kerjani
Copy link

kerjani commented Jul 10, 2018

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

@Rajeshr34
Copy link

@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" }
    }
}

@mufumbo
Copy link

mufumbo commented Jul 12, 2018

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

@Shusshu
Copy link

Shusshu commented Jul 26, 2018

4.8.0-SNAPSHOT works for me

@mice777
Copy link

mice777 commented Aug 15, 2018

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.

@friederikewild
Copy link

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)

@HimanshuNarang
Copy link

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

@CnPeng
Copy link

CnPeng commented Sep 26, 2018

@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,like 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

@PiN73
Copy link

PiN73 commented Oct 2, 2018

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

@sjudd
Copy link
Collaborator

sjudd commented Oct 24, 2018

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

@sjudd sjudd closed this as completed Oct 24, 2018
@EmmanuelMess
Copy link

@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

@HimanshuNarang
Copy link

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.

@EmmanuelMess
Copy link

EmmanuelMess commented Dec 10, 2018

@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..

@jackz314
Copy link

jackz314 commented Dec 30, 2018

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.

@TonyTangAndroid
Copy link

@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.

@TonyTangAndroid
Copy link

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.

aaroncrutchfield added a commit to aaroncrutchfield/NatashasHairStudio that referenced this issue Feb 12, 2019
@eicky
Copy link

eicky commented Mar 13, 2019

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

@jmhabuild
Copy link

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'

@wtnh
Copy link

wtnh commented Aug 7, 2019

@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?

@IgorGanapolsky
Copy link

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

@IkemNwodo
Copy link

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!

@luatnd
Copy link

luatnd commented Jan 10, 2020

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.

@hungntv
Copy link

hungntv commented Jan 12, 2020

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

@wtnh
Copy link

wtnh commented Jan 12, 2020

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'

@mochadwi
Copy link

mochadwi commented Apr 25, 2020

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: facebook/facebook-android-sdk#591 (comment) (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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests