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. In the latest Android Studio v3.5 when we create a new Android project it shows an option either to use new AndroidX artifacts or old Support Libraries. But this guide also explains how to migrate the existing Android project to AndroidX.
For new projects, it’s very easy to move on AndroidX. You can see in the following screenshot.
Migrate Older Android Project to AndroidX
Now the real question comes in, how to migrate older Android studio projects to use AndroidX artifacts? But it’s also very simple as Android Studio has provided a tool for AndroidX migration. But in some scenarios, especially when you have big projects it becomes difficult. Sometimes you have to make changes in all files. But you can follow the following steps to make your AndroidX migration easy.
1. Open your App-level ‘
build.gradle‘ file and make sure that you have set ‘
2. Open your App-level ‘
build.gradle‘ file and 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.
3. In Android Studio’s top menu bar, Go to Refactor -> Migrate to AndroidX, the screenshot is following.
4. 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.
5. 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.
6. Now after the above step, ideally your project should be migrated to AndroidX. But in complex projects it’s not the case, we still need few manual fixes. 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. For that press
command+shift+R to find, validate and replace the following imports in your whole project. You need to replace these in XML files as well.
That’s it. This is how to migrate the Android project to AndroidX. Now you can build your project. It should compile 🙂
Above, I have mentioned the famous imports to replace, but if I missed something, feel free to suggest in the comments.
You can also find other useful helping articles and tutorials in our Coding Articles & Tutorials Knowledge Base.