29

I've been trying to integrate AndroidX into my hybrid React Native project, and I've run into the issue that Jetifier doesn't run on "local" projects. This results in all of my React Native libraries still using the old support libraries. I've put the appropriate lines into my gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true

This works for any remote libraries, but React Native places all of it's libraries as local modules on disk.

I've tried a lot of things, but so far my best solution is a post package-install script that basically manually replaces all of the packages and add/removes libraries to the various gradle scripts.

This is a very manual process and not super sustainable. Is there a better way to handle this issue?

Chubacca
  • 435
  • 1
  • 5
  • 9
  • Here is the issue on React Native GitHub corresponding to your problem. https://github.com/facebook/react-native/issues/23112. Probably, soon it will be fixed, so no problems will be faced with AndroidX usage. – Kamo Spertsian Jan 24 '19 at 16:08
  • Got that script anywhere handy. Would love a gist. Thanks – Brenwell Feb 06 '19 at 16:18
  • Unfortunately not - we just decided to hold off from migrating to AndroidX for now. We didn't end up finishing the script given the unsustainable nature of it. Hopefully the fixes should be merged soon though! – Chubacca Mar 29 '19 at 19:08
  • I did this by forking the repos (about 8) and then redirecting yarn to use the forks: https://github.com/greg7gkb?tab=repositories Instead of scripting, I imported the forked lib into Android Studio and ran Refactor -> Migrate to AndroidX. Good as a temporary solution until above issue is officially resolved. – greg7gkb May 30 '19 at 00:06
  • Is there any better solution than to fork packages and migrate them to androidx manually? After these releases https://developers.google.com/android/guides/releases my react native project fails to build for android. – Taylor Johnson Jun 17 '19 at 23:41

3 Answers3

32

try using the npm Jetifier package below in a postinstall script

https://www.npmjs.com/package/jetifier

From the readme:

Make sure your app is AndroidX
npm install --save-dev jetifier
npx jetify (may take a while)
npx react-native run-android
Taylor Johnson
  • 1,845
  • 1
  • 18
  • 31
  • 1
    I was getting the following error and this answer solved my problem. `package android.support.annotation does not exist` – refik Aug 20 '19 at 12:27
3

Currently, there is no need to install a jetifier separately.

Only use

npx jetify
hong developer
  • 13,291
  • 4
  • 38
  • 68
1

try this --> Right Click on the app folder > Refactor > Migrate to AndroidX & click on migrate

https://github.com/facebook/react-native/issues/25307#issuecomment-504752098

Ryan Saleh
  • 371
  • 4
  • 10