Migration to androidX
If you prefer the reading experience ofMedium you can follow us there as well.
If you’ve ever worked on an android project you must have had the chance to fight the libraries version. Android tried to split the support libraries into smaller pieces, and we got some modularisation, (com.android.support:cardview-v7, com.android.support:recyclerview-v7), but this approach has made things more complicated because of the versions. We are well aware of the mess with the backwards-compatibility-libraries v4, v7, v13, v8, v?.Android decided to make androidx to stop this version confusion so every support library like android.support.v7.recyclerview.extensions.AsyncDifferConfig is now androidx.recyclerview.widget.AsyncDifferConfig.
When we talk about react native android part, first we need to make sure we have compileSdkVersion 28 in android/build.gradle file.
Then in android/gradle.properties we need to add these two lines of code :
After this, we need to go to android studio and pick
Refactor > Migrate to AndroidX.
This will convert your app to androidX but we are currently talking about React Native and that means that we have multiple third-party libraries that also needs to be updated. Jetifier is the answer.
After refactoring with the android studio, you should install jetifier.
1. npm install –save-dev jetifier
2. npx jetify
After this, you can run react-native run-android and that’s it.
you can also add npx jetify to postinstall script like this:
All future Android development will be going into AndroidX. It will be easier to maintain and write code without the mess that was caused by the versions. We hope that these tips will make your migration easier.