Open In App

What is AndroidX Library in Android?

The Android Extension Library, often known as AndroidX, is the new open-source project that is a significant upgrade to the original Android Support Library and can be used to develop, test, package version, and release libraries within Jetpack. The Android Jetpack libraries are part of the AndroidX namespace. In a similar way to the Support Library, AndroidX is developed independently of the Android OS and offers backward compatibility with previous Android versions. By offering feature parity and new libraries, AndroidX packages completely replace the Support Library. In addition, The following features are also included in AndroidX:

Why is AndroidX needed?

To make package names more understandable, the AndroidX library has been redesigned. As a result, the Android hierarchy will no longer include any classes beyond those included with the Android operating system. Instead, AndroidX will include all other libraries and dependencies. Therefore, any future developments will be updated in AndroidX.



Migrating to AndroidX

Moving from the Android Support Library to AndroidX is now the appropriate course of action.

Migrating Instructions

Before you begin the transition to AndroidX, back up your project because migration will change many of the files in your project.



Step 1: Update to Support Library version 28

It is not advised to upgrade from an older version of the Support Library straight to AndroidX. In addition to dealing with namespace changes, you would also need to deal with API changes between AndroidX and the previous version.

Therefore, it is advised that you update to version 28, take care of all the API changes, and make sure your program compiles with version 28.
In other words, just the package name differs between Support Library version 28 and AndroidX version 1.0; all the APIs are the same. As a result, there shouldn’t be many issues to fix while switching from version 28 to AndroidX.

Step 2: Enable Jetifier

Jetifier helps in the migration of external dependencies to AndroidX. To make certain dependencies compatible with applications utilizing AndroidX, Jetifier will alter its byte code. Jetifier won’t move your created code or alter your source code. Add the following to your Gradle file to enable Jetifier in your app:

android.useAndroidX=true
android.enableJetifier=true

The AndroidX version of a library will now be imported instead of the previous Support Library version when using code auto-completion.

Step 3. Update dependencies

Update all third-party libraries, like Volley, Glide, Retrofit, and SqlDelight, to the most recent version before beginning the migration. Failure to do so could lead to compilation errors that are not known why. Jetifier won’t alter any code-generating libraries you’re using. Therefore, you must ensure that the code generation library is appropriate for AndroidX.

Step 4: Update your source code

You can use Android Studio to upgrade your source code to use AndroidX. You can update your source code using the “Migrate to AndroidX” option on the “Refactor” Menu if you are using Android Studio 3.2 stable or higher. This approach is advised since Android Studio can review your source code and determine the best refactoring options.

Open an Existing Project => Android Studio => Refactor Menu => Migrate to AndroidX

The Refractor window at the bottom will be opened after analysis and accept the changes to be done.

 

Concluding Remarks: If you haven’t switched to Android X, now is a great time to do so and benefit from the accelerated app development that the Jetpack frameworks provide.

Article Tags :