Android Developers
Published in

Android Developers

Illustration of a laptop with the Android on the screen and other tech objects in the background.

Migrating to AndroidX: tips, tricks, and guidance

Take advantage of the latest Jetpack has to offer.

Why migrate?

  1. The Android Support Library has reached the end of its life. 28.0 was the last release of the Android Support namespace and the namespace is no longer maintained. So, if you want bug fixes or new features that would have previously gone into the Support Library, you need to migrate to AndroidX.
  2. Better package management. With AndroidX, you get standardized and independent versioning, as well as better standardized naming and more frequent releases.
  3. Other libraries have migrated to use the AndroidX namespace libraries, including Google Play services, Firebase, Butterknife, Mockito 2, and SQLDelight among others.
  4. All new Jetpack libraries will be released in AndroidX namespace. So, for example, to take advantage of Jetpack Compose or CameraX, you need to migrate to the AndroidX namespace.

Preparing to migrate

  • back up your project. If you’re using source control tools, it is still recommended that you make a backup, because migration will change many of the files in your project.
  • create a new branch on which to make the migration changes.
  • if possible, suspend or minimize development (at least don’t try to do refactoring or pull in new features) during the migration, as this will help reduce the number of merge conflicts that could happen.

Migrate

Step 1: Update to Support Library version 28

Step 2: Enable Jetifier

android.useAndroidX=trueandroid.enableJetifier=true

Step 3. Update dependencies

  • the third-party code you’re using is not compatible with AndroidX. In this case, a stack trace similar to the one below will show you that it’s trying to pull in the old version of the Support Library:
Error : Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy |Reason: Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy
  • if you have a project that’s partially migrated, you might get a duplicate class error, where it’s trying to pull in the same code from both the Support Library and AndroidX. The stack trace will show you something like this:
Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)

Step 4: Update your source code

  • Android Studio
  • manual update
  • Bash script

Those pesky exceptions

Version configuration files

ext.versions = [    ‘drawer’ : ‘28.0.0’,    ‘rview’ : ‘28.0.0’]implementation “com.android.support:drawerlayout:${versions.drawer}”implementation “com.android.support:recyclerview-v7:${versions.rview}”
ext.versions = [    ‘drawer’ : ‘28.0.0’,    ‘rview’ : ‘28.0.0’]implementation “androidx.drawerlayout:drawerlayout:1.0.0”implementation “androidx.recyclerview:recyclerview:1.0.0”
ext.versions = [    ‘drawer’ : ‘1.0.0’,    ‘rview’ : ‘1.0.0’
]
implementation “androidx.drawerlayout:drawerlayout:${versions.drawer}”implementation “androidx.recyclerview:recyclerview:${versions.rview}”

ProGuard and build scripts

Get the latest stable version

implementation ‘com.android.support:appcompat-v7:28.0.0’
implementation ‘androidx.appcompat:appcompat:1.1.0-alpha01’
implementation ‘androidx.appcompat:appcompat:1.0.2’

More help and resources

Final thoughts

--

--

Articles on modern tools and resources to help you build experiences that people love, faster and easier, across every Android device.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store