AndroidX Migration

"AndroidX Migration"

Google has recently introduced a new way of organizing support libraries called AndroidX.

Android Jetpack is a suite that provides tools, components and guidance to build Android Apps. Android jetpack provides various kinds of components such as Data Binding, Media & playback, Notifications, Permissions and many more. One of the important reason to use Jetpack is, it provides backword compatibility to Android API’s.

For more details about Android Jetpack visit here: Android Docs

AndroidX is also such kind of library provided by Android Jetpack. Basically it is An advanced version of Android Support libraries. Version 28.0.0 is the last release of the Support Library. There will be no more android. support library releases. All new feature development will be in the AndroidX namespace.

Need of Migration into AndroidX

AndroidX is a major improvement to the original Android Support Library All packages in AndroidX live in a consistent namespace starting with the string AndroidX. The Support Library packages have been mapped into corresponding AndroidX. packages.

From August 1, 2019 , support for 64-bit architecture is made compulsory by Google Play due to performance improvements. But for each native 32-bit architecture you support/use you must include the corresponding 64-bit architecture. Hence, it became a confusing task for developers to manage different versions for each support library.

"Need of AndroidX Migration"

The AndroidX library contains the existing support library and also includes the latest Jetpack components. You can continue to use the support library. Old artifacts (those versioned 27 and earlier, and packaged as android.support. will remain available on Google Maven. However, all new library development will occur in the AndroidX library.

1. Prerequisites

Migrating your current Android Project to AndroidX is really simple. But before migration, you will have to check the following:

  1. Android studio version must be 3.2+
  2. You must update Compile SDK version to Android 9.0 (API level 28) or higher

If your android studio version is 3.2.x you have to use gradle build version 3.2.1. If you are using android studio version 3.3.1 then your gradle build version should also be 3.3.1. If any mismatch happen in version means it will throw error.

2. Steps to do Migration

Migration can be done in two ways:

  1. Using refactor command
  2. By refractor from Menu Bar

Using refactor command

You can simply add below two lines in your gradle.properties for migration.

android.useAndroidX=true
android.enableJetifier=true

gradle.properties

By refractor from Menu Bar

  1. Go to Refactor menu
  2. Select ‘Migrate To AndroidX’ select_migrate_to_androidx
  3. Depending on your project dependencies, there might occur some errors after migration and might need to resolve them manually. Hence, you can take backup of your project. (Taking backup of the project is optional) click_on_migrate
  4. Now this will show the refactor window with the list of all the files using android support libraries. Just click Do Refactor. do_refactor

For more details you can refer:

Thank You!


Written by@Siddhi Rajput
Siddhi Rajput, explain with words and code.