This year, Google announced at its developer event Google I/O the creation of a new set of libraries, tools and architectural guidance for Android: AndroidX, better known as Android Jetpack. But what is Android Jetpack? It is a series of unbundled libraries that are not linked to any particular version of Android, which allows developers to include the newest features in older versions of Android.'
What's new in Android Jetpack
In addition, Android Jetpack helps perform more tasks, reducing the number of lines of code, by providing the repeating plate to handle repetitive tasks. Its components can be grouped into four categories: Foundation, UI, Architecture and Behavior. Also, Android Jetpack brings 5 new components:
Work Manager: A task scheduler.
Navigation: This component enables you to design, edit and adjust the navigation of your application.
Paging: Divides the data to be loaded in parts, reducing the waiting time.
Slices: They show a fragment of the content of your application on Google, you can see a great variety of static and interactive content about it.
Android KTX: It’s a collection of modules consisting of extensions that optimize the APIs of the Android platform for Kotlin.
How to update to AndroidX
Before even thinking about migrating to AndroidX, you must update all your current support libraries to their latest versions. To change old artifacts into new ones will only require changing the names of the packages. This means, in most cases, being in version v28.0.0 of the support libraries. However, some libraries use other version schemes: Android KTX must be updated to v0.3.
This preparation is excellent for discovering parts of your base code that cannot work with the updated libraries and so you can proceed to update without problem.
According to the official Google guide to update, you have to download the canary version of Android Studio, although you can keep the stable and canary versions on your machine. Open your project in the Canary version and then go to the Refactor menu and select Refactor to AndroidX... now Android Studio will scan your project and change your libraries to the new AndroidX structure.
This is risky because in several cases the projects are completely broken, the imports aren´t mapped correctly, and it is possible that you be forced to do a lot of manual work. In other cases, most of the changes may work fine, but you may have problems, such as having the old library androidx.app.Fragment in the code with the old support.v4.Fragment as the imported class type of "errors". Fortunately, these types of errors are easy to fix.
Problems with the migration to AndroidX
The next step, which should be done automatically by Android Studio, was to change / add dependencies in the build.gradle modules.
For its part, jetifier is a useful tool that automatically migrates its dependencies to AndroidX at the time of compilation, saving the need to import each dependency that you use to have an AndroidX version before you can migrate. However, the jetifier only works on packaged devices, it doesn´t work with source code. You will have to update it manually.
It is advisable to use a small script that allows you to be sure that all package names were converted to Android Jetpack. Fortunately Google provides an old csv file to the new package names that will be very useful to program that script.
For now, the artifacts of the support library are in disuse and all future development is being done in AndroidX, so this migration is inevitable. For now, there are no plans to abandon the support libraries, so if a component is available for the support library and Android Jetpack at the same time, you can still choose which implementation you want to use. However, version 28.0.0 will be the latest version of android.support. After that, you will have to update to the AndroidX namespace and architecture.