Migration to androidX

Migration to androidX

Why?
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 :
android.useAndroidX=true
android.enableJetifier=true

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: 

androidX after refactoring run npx jetify

Conclusion

All future Android development will be going into AndroidX. It will be easier to maintain and write code without the mess that was caused with the versions. We hope that these tips will make your migration easier.

 

Luka @ Vicert

Author: Luka @ Vicert

Leave a Reply

Your email address will not be published. Required fields are marked *