AndroidX is an open-source project by Google that provides a major improvement to the original Android Support Library. AndroidX is replaced the Support Library. Like support library, Google keeps AndroidX is independently from the Android OS and provides backward-compatibility across Android releases. AndroidX package structure is to encourage smaller and more focused libraries.
AndroidX replaces the original support library APIs with packages in the
androidx namespace. Only the package and import names changed. Class, method, and field names did not change in migration.
android.support.v7.widget.RecyclerView is changed to androidx.recyclerview.widget.RecyclerView
android.support.v7 is replced by androidx.
Migrating existing project:-
Before start migration, we need to make sure to follow the below things:-
1. Android studio version should be higher than 3.2, You can check your android studio version from About Android Studio section. also use the latest Gradle version. Check project level Build.Gradle file to change the version.
2. Target SDK version and Compile SDK version should be 28 or greater. Check your app level Build.Gradle file to change target and compile SDK version.
3. Take a backup of your project.
4. Add below properties to gradle.properties file. You can find this file on Project Level.
A.) android.useAndroidX: set to true, the Android plugin uses the AndroidX library instead of a Support Library. The value is false by default.
B.) android.enableJetifier: set to true, the Android plugin automatically migrates existing third-party libraries to use AndroidX. The value is false by default.
Let’s start migration:-
1. Click Refactor from the menu in Android studio.
2. Then Click on Migrate to AndroidX from Refactor dropdown.
3. After that, It will ask you to take a backup of the whole project. If you have already taken the backup then ignore this step.
4. After the backup process clicks on Migrate, It will show list all support library where we are using in this project. Just click on Do Refactor and wait for some time.
5. After some time, you can see the project all support library replaced by the AndroidX library. Most of the support library will merge automatically and few we need to replaced manually. If you found any error, Fix it manually. and test your app carefully. The application could crash due to incorrect auto-correction during migration.
That’s it. Enjoy Coding using AndroidX. 🙂