What is AndroidX?
It’s a new library improved from the Android support libraries that will be used to develop within the jetpack. Android X replaces the support libs by delivering equally and new libraries. Moreover, this includes the below features:
- All support libraries are separately maintained and updated
- With 28 Api level android development have to use AndroidX library.
- Support the legacy libraries with AndroidX version
- A library namespace prefix is `androidx’. Check this page
Android Jetpack is a new set of libraries, tools and architecture guidance designed to help the developer to increase an android development with high-quality apps. Jetpack is used to write an android code with the production-ready template. There are four components: Architecture, Foundation, Ui and Behaviour. These components will help you to follow the best practices, and provide a boilerplate code (Very big hectic for me to start a new app). This means you can adapt each commonest at your own speed and time. The unbundled Jetpack libraries have all been moved into the new androidx.* namespace.
From the above pictures, We have some new libraries:
- Navigation stable release
- Paging stable release
- WorkManager stable release
- Android KTX stable release
- Slices alpha release
How AndroidX related to Jetpack ..?
Jetpack is a set of libraries, which provide tools and recommendation to create a high-quality app. On the other hand, AndroidX is a library itself, whose feature might be in Android Jetpack. Like Android KTX and slices belongs to AndroidX and Jetpack also.
Migrate to AndroidX
- Backup the whole project manually. Although android studio gives you the option to backup before migrating its helpful to have one more backup for incase.
- If you are using git than check out the new branch for refactoring
- Check Android Studio version must be 3.2 or newer.
Now grab a coffee this may take a while 😅
In Android Studio check the menu Refactor>Migrate to AndroidX. If you check this, you may face the following error if your project Gradle is not on latest one:
How to solve this :
- Compile Sdk version on 28
- Gradle version must be 3.4.2 or newer
- Update `gradle.properties` with this:
Sync the project and Fix Gradle wrapper and re-import project. If you face Gradle wrapper error.
Now we are good to go to Migrate to AndoridX. Hit again to Migrate to Android from Refactor Options and do refactor like this
After fixing all error, maybe on runtime for some library give an error like a butterknife, room. You should compile the app and run all test by going through every screen to make sure that everything works perfectly after this big migration.
Here we are at the end of Android X migration and our app is working fine. Here are some tips to make sure migration will be executed perfectly:
- Backup the project (very important)
- Work on the new branch
- Read AndroidX documentation as well
- Ask a question on StackOverflow or google group if have confusion
Good luck, If you find this blog helpful do clap for me 👏