Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidX migrate dependency / libraries

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?

like image 787
Khemraj Sharma Avatar asked Sep 26 '18 13:09

Khemraj Sharma


People also ask

How do I migrate to AndroidX library?

With Android Studio 3.2 and higher, you can migrate an existing project to AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar. The refactor command makes use of two flags. By default, both of them are set to true in your gradle.

Why should I migrate to AndroidX?

Why you should migrate your app to AndroidX? Unlike the Support Library, AndroidX packages are separately maintained and updated. The androidx packages use strict Semantic Versioning . So you can update AndroidX libraries in your project independently.

Is AndroidX backwards compatible?

The androidx namespace comprises the Android Jetpack libraries. Like the Support Library, libraries in the androidx namespace ship separately from the Android platform and provide backward compatibility across Android releases.

What is the difference between Jetpack and AndroidX?

Jetpack is a suite of libraries, tools, and guidance to help developers write high-quality apps easier. Jetpack comprises the androidx. * package libraries, unbundled from the platform APIs.


2 Answers

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.

like image 115
Kousic Avatar answered Oct 20 '22 10:10

Kousic


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.

like image 45
Khemraj Sharma Avatar answered Oct 20 '22 11:10

Khemraj Sharma