AndroidX migration in a nutshell

By | May 4, 2019

Why AndroidX

By the introduction of AndroidX, clear distinction is now made between the operating system packages and the support libraries or dependencies used to extend it. Going forward, the former (android OS) is going to be inside android and the support libraries inside  androidx package hierarchy.

Not only does this make things clearer but it also enables using different versions of the former support library independently:

Before androidX:

After AndroidX:

 

What are the migration steps?

1- Upgrade compileSdkVersion to 28

This requires updating the support libraries to version 28.

 

2- Upgrade Android Gradle plugin and kotlin

Inside app build.gradle:

 

3- Run migration tool

Run the migration tool in android studio from Refactor --> Migrate to AndroidX.

Backup your project when prompted.

This process takes a while depending on the size of your project, so be patient.

 

4- Manual migration of some package names

If your project does not compile after the previous step, you will need to do this. Even after successful compilation you still might need to look into this. One example could be manual migration of  android.support.design.R to com.google.android.material.R when being used as full name inside the code. For complete mappings refer to here.

Also if you are using  RecyclerView for which the app:layoutManager is defined in the xml as a hardcoded string, the migration tool might not change it to androidX automatically, so do not forget to replace android.support.v7.widget to androidx.recyclerview.widget  in  app:layoutManager . Not doing so causes crash at runtime.

 

5- Make release build and test it

The new shrinking tool (R8 shrinking tool) is enabled by default and might cause build problems. Disable it if running into release build issues by putting this in gradle.properties:

android.enableR8=false

Test your app thoroughly. AndroidX migration can be a huge change depending on your project.

Happy Migrating!

Leave a Reply

Your email address will not be published. Required fields are marked *