Open In App

What is AndroidX Library in Android?

Last Updated : 12 Jul, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • All AndroidX packages are located in a single namespace that begins with the initials androidx. The comparable androidx.* packages have been mapped to the Support Library packages. 
  • AndroidX packages are individually updated and maintained, in contrast to the Support Library. From version 1.0.0 onward, the AndroidX packages strictly adhere to semantic versioning. A project’s AndroidX libraries can be independently updated.
  • The AndroidX library will be the location for all future Support Library development. This covers both the addition of fresh Jetpack components and the upkeep of the original Support Library objects.

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.

  • com.android.support.** : androidx.
  • com.android.support:appcompat-v7 : androidx.appcompat:appcompat
  • com.android.support:recyclerview-v7 : androidx.recyclerview:recyclerview
  • com.android.support:design : com.google.android.material:material

Migrating to AndroidX

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

  • The Android Support namespace was last released in version 28.0 of the Android Support Library, and it is no longer being developed. Therefore, AndroidX will be the platform for all new features and bug fixes.
  • With AndroidX, you get improved package management, standardized and independent versioning, more consistent naming, and more frequent releases.
  • Google Play services, Firebase, Butterknife, Mockito 2, and SQLDelight are just a few of the libraries that have switched to using the AndroidX namespace libraries.
  • In the AndroidX namespace, all incoming Jetpack libraries will be made available. Therefore, you must switch to the AndroidX namespace if you want to use features like Jetpack Compose or CameraX.

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.

Migrating To AndroidX

 

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.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads