AndroidX migration: what ,why, how?

Getting tired to solve versioning problem of your support library? No more tension! Now AndroidX is ready to solve ur problem.

SHISHIR
PROGRAMMING LITE
3 min readJan 13, 2020

--

AndroidX

What is AndroidX?

  • AndroidX is the open-source project that is introduced along with Android Jetpack.
  • Basically, it is a major improvement to the original Android Support Library.
  • Like the Support Library, AndroidX also ships separately from the Android OS and provides backwards-compatibility across Android releases.
  • The old support libs up to version 28 will remain available as they are, but the new versions of the support lib will be released under the AndroidX package refactor, starting from version 1.0.0.

Why you should migrate your app to AndroidX?

  • Unlike the Support Library, AndroidX packages are separately maintained and updated. The androidx packages use strict Semantic Versioning . So you can update AndroidX libraries in your project independently.

Those frustrating “All com.android.support libraries must use the exact same version specification” messages should become a thing of the past!

  • The android support library will be never maintained by Google under the support library namespace. So if you want to find fixes of a bug in support library you must have to migrate your project in AndroidX.
  • Google play services, Firebase, Mockito 2, etc are already have migrated to AndroidX.

Do you want to make a super-high-quality, memory-efficient Android app? So you should focus on one of the most important optimization techniques in android: Memory leaks. You will find details of memory leaks from this article Memory Leaks in details in Android.

How to migrate your new project to AndroidX

Step 01: Set the compile SDK version to Android 9.0 (API level 28) or higher as minimum compile sdk version required for androidx is 28.

Step 02: Put these two flags in your gradle.properties file.

Here,

  • android.useAndroidX: The flag is false by default if it is not specified. When set to true, the Android plugin uses the appropriate AndroidX library instead of a Support Library.
  • android.enableJetifier: The flag is also false by default if it is not specified. When set to true, the Android plugin will automatically convert third party libraries to AndroidX.

How to migrate your existing project to AndroidX

In the latest versions of Android Studio (Android Studio 3.2 and higher) the migration to AndroidX is quite easy. Open your Android Studio.

Step 01: Go to Refactor > Migrate to AndroidX from the menu bar.

Step 02: Now Android Studio will ask if you want to save a backup copy of your project in a .zip file so that in case of any problems, you can get your project back. So backup your project.

Step 03: No more steps needed :) the refactor command will automatically add android.useAndroidX and android.enableJetifier flags with value true in gradle.properties file.

Before migrating your existing project, it is strongly recommended to backup your project.

Bugs of migrating existing project

  • If you build app, and find some errors after migrating, then you need to fix those minor errors. You will not get stuck there, because that can be easily fixed.
  • 3rd party libraries are not converted to AndroidX in directory, but they get converted at run time by Jetifier, so don’t worry about compile time errors, your app will run perfectly.

To make a secure app you must keep your API Keys in a secured place in your app. Find details from this article Securing API Keys in Android APP.

Conclusion

The support library artifacts are being deprecated and all future development is going into AndroidX, so there’s no avoiding this migration. Hopefully, though, these tips will give you a clearer transition path.

Thanks for reading the article. Be sure to give claps if you find this article helpful.

Happy Coding :)

Happy Coding :)

--

--

SHISHIR
PROGRAMMING LITE

{ 'designation' : 'Lead Software Engineer' , 'hobby' : [ 'Music', 'Photography', 'Travelling' ] ,’email’: ‘shishirthedev@gmail.com’ }