AndroidX migrate dependency / libraries
Asked Answered
S

3

10

I have successfully migrated my project to AndroidX. App is running perfectly, but I am getting compile time errors, because my dependencies use support package.

image1

image2

Reason of this error

Because PhotoView is a dependency class, which uses android.support.v7.widget.AppCompatImageView which is no more available in my project. Because it is now androidx.appcompat.widget.AppCompatImageView

Project still run?

Yes, android.enableJetifier convert this dependency to AndroidX at runtime, but I want to get rid of compile time errors.

Is there a quick fix for now?

Spare answered 26/9, 2018 at 13:28 Comment(1)
Which version of PhotoView are you using? The latest release (2.2.0 as of now) uses AndroidX.Ritchie
S
3

I solved this issue by deleting .idea folder and syncing project again.

This seems a bug of IDE not Jetifier, it does not re-sync dependencies after migrating. Jetifier does its work well. It converts all dependencies support libraries into androidx at building time. See @this post for good explaination.

Spare answered 1/11, 2018 at 19:21 Comment(0)
W
12

If you depend on a library that references the older Support Library, Android Studio will update that library to reference androidx instead via dependency translation. Dependency translation is automatically applied by the Android Gradle Plugin 3.2.0-alpha14, which rewrites bytecode and resources of JAR and AAR dependencies (and transitive dependencies) to reference the new androidx-packaged classes and artifacts. We will also provide a standalone translation tool as a JAR.

I see (using ./gradlew app:dependencies) that rxbinding's design dependency is updated to the new com.google.android.material dependency. Passing com.google.android.material.snackbar.Snackbar to a library function that references android.support.design.widget.Snackbar themselves makes Android Studio show a compiler error, but actually compiling and running the app works. I assume AS can't really handle these changes yet.

It seems there are some caching issues, removing .idea/libraries and performing a Gradle sync makes the errors disappear.

Wynellwynn answered 15/10, 2018 at 5:42 Comment(2)
Perhaps it was an cache, cause I am not getting that error now. I did not clear idea.Spare
in my case, in runtime, the crash still happened. even I already delete the .idea & .gradle libs. so I endedup using jetifier-standalone instead to do the migration, and add the aar manually T_TOralla
S
3

I solved this issue by deleting .idea folder and syncing project again.

This seems a bug of IDE not Jetifier, it does not re-sync dependencies after migrating. Jetifier does its work well. It converts all dependencies support libraries into androidx at building time. See @this post for good explaination.

Spare answered 1/11, 2018 at 19:21 Comment(0)
S
1

My fix for this was converting the library with the compile time error to AndroidX and submitting a pull request to the library.

Servitude answered 27/9, 2018 at 16:25 Comment(1)
That can be a solution individually, but still need some unique solution.Spare

© 2022 - 2024 — McMap. All rights reserved.