Migrating to AndroidX: The time is right

Youtube Video:   https://youtu.be/kYxmpt4yNjA(in English)
                             https://youtu.be/0jPJcgwq1RQ(in
Hindi)

Google has replaced the Android Support Library with the latest AndroidX Library. AndroidX library provides backward compatibility whenever the new versions of Android are released. All new Jetpack libraries will be released in AndroidX namespace.

Why migrate?

The time is right now to migrate from using the Android Support Library to AndroidX. There are four reasons behind this:

  1. The Android Support Library has reached the end of its life. 28.0 was the last release of the Android Support namespace and the namespace is no longer maintained. So, if you want bug fixes or new features that would have previously gone into the Support Library, you need to migrate to AndroidX.
  2. Better package management. With AndroidX, you get standardized and independent versioning, as well as better standardized naming and more frequent releases.
  3. Other libraries have migrated to use the AndroidX namespace libraries, including Google Play services, Firebase, Butterknife, Mockito 2, and SQLDelight among others.
  4. All new Jetpack libraries will be released in AndroidX namespace. So, for example, to take advantage of Jetpack Compose or CameraX, you need to migrate to the AndroidX namespace.

Prerequisites

Before you migrate, bring your app up to date. We recommend updating your project to use the final version of the support library: version 28.0.0. This is because AndroidX artifacts with version 1.0.0 are binary equivalent to the Support Library 28.0.0 artifacts.

Migrate an existing project using Android Studio

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.properties file:

android.useAndroidX=true

The Android plugin uses the appropriate AndroidX library instead of a Support Library.

android.enableJetifier=true

The Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries.

Note: The built-in Android Studio migration might not handle everything. Depending on your build configuration you may need to update your build scripts and Proguard mappings manually. For example, if you maintain your dependency configuration in a separate build file, use the mapping files mentioned below to review and update your dependencies to the corresponding AndroidX packages.

Migrate Step:

Step 1. Open project in android studio.

Step 2. Open SDK and install latest "Android SDK Build-Tool" version.

Step 3. Open build.gradle present inside project folder(path: project/build.gradle). Make sure that you have ‘com.android.tools.build:gradle‘ version greater than or equal to 3.2.0. Otherwise, add the following latest version.

classpath 'com.android.tools.build:gradle:3.5.3'

Step 4. Open build.gradle present inside app folder(path: app/build.gradle).

Update compileSdkVersion to 28 or above that

Step 5. Go to Refactor menu bar option and click on Migrate to AndroidX..

Step 6. After pressing the Migrate to AndroidX option, you would see a popup, asking for a backup. You can check that and press the Migrate button.

Step 7. Now Android Studio will show you the list of all the changes it is going to make, and usages of them. You can go through those changes and the press the Do Refactor button.


Step 8. After doing all these step, ideally your project should be migrate to AndroidX.

But in complex peoject it's not that much easy, we still need few manyal foces. After completing the above steps, try to build your project. If the build doesn’t succeed, go for the following manual fixes.


Manual Fixes in AndroidX Migration

You need to make sure that the following libraries are successfully converted to the subsequent libraries. You need to replace these in XML files as well.

android.support.v7 -> androidx.appcompat

android.support.annotation -> androidx.annotation

android.support.v7.widget.RecyclerView -> androidx.recyclerview.widget.RecyclerView

android.support.v7.widget -> androidx.appcompat.widget

android.support.v4.content -> androidx.core.content

android.support.v7.widget.CardView -> androidx.cardview.widget.CardView

android.support.v4.util -> androidx.core.util

In gradle.properties file, check below mwntion enableJetifier and useAndroidX present or not, if not present then add it.

android.enableJetifier=true

android.useAndroidX=true


This is How to migrate the Android project to AndroidX.

Facebook Page: https://www.facebook.com/DreamsAppsStore

YouTube Channel: https://www.youtube.com/channel/UCBpa57i2Y8BFh7BhH4TQ_zw

Google Play: https://play.google.com/store/apps/dev?id=8456069187984922570

Post a Comment

0 Comments