Ultimate Guide to Migrate Android Project to AndroidX

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.

Video Tutorial

For new projects, it’s very easy to move on AndroidX. You can see in the following screenshot.

Create Project With AndroidX Artifacts / Library
Create Project With AndroidX Artifacts / Library

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 ‘compileSdkVersion‘ to 28.

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.

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

3. In Android Studio’s top menu bar, Go to Refactor -> Migrate to AndroidX, the screenshot is following.

Refactor -> Migrate to AndroidX
Refactor -> Migrate to AndroidX

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.

Do Refactor to AndroidX
Do Refactor to AndroidX

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.

  1. android.support.v7 -> androidx.appcompat
  2. android.support.annotation -> androidx.annotation
  3. android.support.v7.widget.RecyclerView -> androidx.recyclerview.widget.RecyclerView
  4. android.support.v7.widget -> androidx.appcompat.widget
  5. android.support.v4.content -> androidx.core.content
  6. android.support.v7.widget.CardView -> androidx.cardview.widget.CardView
  7. android.support.v4.util -> androidx.core.util

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.

Please share this post:
Native Mobile Application Developer (Android + IOS) having experience in Java, Swift, Kotlin, Objective C, Unity, C#, C/C++, NODE JS & PHP.

4 thoughts on “Ultimate Guide to Migrate Android Project to AndroidX

  1. configurations.all {
    resolutionStrategy.force ‘com.google.code.findbugs:jsr305:1.3.9’
    resolutionStrategy.force ‘com.android.support:support-annotations:26.1.0’

    androidTestCompile(‘androidx.test.espresso:espresso-core:3.3.0-alpha02’, {
    exclude group: ‘com.android.support’, module: ‘support-annotations’
    how to change the above code to convert to androidx

  2. Have you ever thought about creating an ebook or guest authoring on other sites? I have a blog centered on the same ideas you discuss and would really like to have you share some stories/information. I know my audience would appreciate your work. If you’re even remotely interested, feel free to shoot me an e mail.

Ask a Question

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

%d bloggers like this: