Stay Connected

PERSONAL BLOG

Migrating to AndroidX

While releasing update on Play Store following message display if targeted API level is less then 28

From August 2019, new apps must target at least Android 9.0 (API level 28).
From November 2019, app updates must target Android 9.0 (API level 28).

This article will cover how to update or migrate to AndroidX aka Jetpack

1-What is AndroidX?

AndroidX (Android Extension library) is the new era of Android Support library recommended by Google. It helps developer accelerate the development, also eliminate boilerplate code to handle repetitive tasks like managing the application lifecycle to make sure that the developers build high quality and robust apps. AndroidX supports newer OS features on older versions of Android along with newer device-specific UX, new features under Android KTX, debugging, testing. To keep in mind for smaller and more focused packages, AndroidX redesigns the packages structure such that both the names of Architecture Components and support libraries are simplified. This should help make clear that which dependencies should be included in the APK.

Android Jetpack components are divided into:

  • Foundation- This covers core system capabilities, such as AppCompat.
  • UI- This is the category for UI-focused components, including Fragment and Layout, but also for components that aren’t restricted to smartphones, such as Auto, TV, and Wear OS by Google (formerly Android Wear).
  • Architecture- This is where you’ll find modules to help you handle the challenges surrounding data persistence and the application lifecycle.
  • Behavior- This category contains modules such as Permissions, Notifications, and Sharing.

Android Jetpack

2- Migrate to AndroidX

NOTE: Upgrade your app to latest Support libs.

When you are ready to update to Jetpack, make sure your app is upgraded to the latest versions of Gradle and AppCompat. This will ensure the refactor is only changing package names, and are not bigger issues related to library updates.

Use the Refactor tool to update your Project

Now project needs to target API level 28, and you will need to add the following lines to your gradle.properties:

android.enableJetifier=true

android.useAndroidX=true

The first flag tells the Android Plugin to use AndroidX packages instead of AppCompat, and the second flag will enable the Jetifier, which is a tool to help with using external.

3- Refactor

Once you have upgraded your project, use an Android Studio utility to do the refactor. Android Studio 3.2 has a refactoring feature that can update your code, resources, and Gradle configuration to reference the AndroidX artifacts and classes. To refactor your project, select > it from the menu tool bar: Refactor->Refactor to AndroidX:

4- Jetifier

The jetifier is a handy tool that automatically migrates your dependencies to AndroidX at build time. There’s an important limitation to note: the jetifier only works on packaged artifacts. It does not work on your source code, which you are expected to update yourself.

Unfortunately, your app may have code which is neither a packaged artifact nor source code you control: generated code. You neither write nor maintain it, but it’s compiled as if it’s your own source code. It doesn’t make any changes to libraries or external dependencies. Google recently announced a stand-alone option for running Jetifier. You can even run a “reverse mode” which will “de-jetify” code (which will be very useful for debugging).

Resources

Adnan Sattar

A self-driven productive Software Engineer who thrives in highly pressurized and challenging working environments by constantly improving skills. Eager to grasp new ideas and concepts from the environment.

Leave a Reply

Recent Comments

    Stay Connected

    Instagram Feed

    Categories

    ×
    %d bloggers like this: