Issues using AndroidX and React Native
Asked Answered
I

3

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?

Impaste answered 10/11, 2018 at 2:27 Comment(5)
Here is the issue on React Native GitHub corresponding to your problem. github.com/facebook/react-native/issues/23112. Probably, soon it will be fixed, so no problems will be faced with AndroidX usage.Koala
Got that script anywhere handy. Would love a gist. ThanksOrthogenetic
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!Impaste
I did this by forking the repos (about 8) and then redirecting yarn to use the forks: 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.Quaquaversal
Is there any better solution than to fork packages and migrate them to androidx manually? After these releases developers.google.com/android/guides/releases my react native project fails to build for android.Poetaster
P
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
Poetaster answered 19/6, 2019 at 19:14 Comment(1)
I was getting the following error and this answer solved my problem. package android.support.annotation does not existLeifeste
D
3

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

Only use

npx jetify
Decree answered 7/4, 2021 at 23:38 Comment(0)
P
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

Philomel answered 23/6, 2019 at 14:24 Comment(1)
Wow android studio made something easy for once!Cohort

© 2022 - 2024 — McMap. All rights reserved.