A step-by-step guide for migration to AndroidX

Pranav Bhoraskar
The 101 Times
Published in
3 min readMar 15, 2020

World of Android is a fast changing ecosystem with new introductions coming every year at Google I/O. Keeping track of all the latest developments and migrating your projects towards newer features and technologies has always been a challenging endeavour. A standout introduction at the I/O 2018 was AndroidX package within Jetpack library.

Why AndroidX?

With Android Support Library being no longer maintained and the current development moving to AndroidX, the introduction of androidx namespace saw the restructuring of the library packages while maintaining the backward compatibility for the various Android releases. These packages are shipped and maintained separately from the AndroidOS.

Semantic Versioning of the androidx packages was another feature which was introduced with AndroidX.

With support libraries no longer being maintained and other libraries also moving towards androidx, a need for migration to AndroidX was felt in our projects as well. Hence, our team at Shop101 decided to take on the task of migrating our codebase to AndroidX.

Migrating to AndroidX

Step 1

Firstly, we made sure that the Shop101 app had the latest support library version 28.0.0. Upgrading the library version led to various compilation errors such as unrecognised nullable parameters. Moving to the next step required a clean build.

Step 2

We had to make sure that we have Android Studio version 3.2+. Android Studio 3.2 enabled us to simply go and hit Refactor -> Migrate to AndroidX from the menu and the following properties were added to the gradle.properties file.

After adding the above properties, we ran the project and the above plugins took care of migrating the project to AndroidX libraries.

Even though this looked like a simple 2-step process, the migration was not yet complete and we encountered a number of issues ranging from unsuccessful import migrations to compile-time and run-time errors in the codebase.

Pitfalls

Some major issues we faced during the migration process which had to be tackled for a successful compilation of the project:

  • The scripts could not replace a few libraries falling under android.support.design. These required manual efforts to migrate them to androidx namespace.
  • We had to replace nullable parameters by non-nullable parameters manually to resolve the compile time errors. E.g.:
Replacing ViewHolder? with ViewHolder in onBindViewHolder()
  • As Jetifier (the standalone tool for migration to androidx packages) does not work on the source code, updating the source code required manual efforts once the scripts updated the libraries successfully.
  • We then ensured that all the Android libraries in the project are up to date.

Once the entire process was completed, we moved on to the next phase in our migration process — Quality Analysis.

Quality Analysis

Our awesome QA team played an important part in this migration. We performed multiple rounds of testing which spanned from UI testing to End-to-End functionality testing to ensure a successful migration.

Release

We started with a limited rollout of the migration and moved towards a larger user base in successive rollouts with the aim of ensuring a bug-free experience for our users.

Conclusion

With Google pushing towards androidx, this migration exercise is an inevitable step as the Android developer community moves away from the support library artifacts. The migration project was a tremendous learning experience for us and we hope our experience will help you! Let us know about your experiences in the comments.

Happy Coding!

Here is a link for your reference :

--

--