使用 AndroidX 和 React Native 的问题 [英] Issues using AndroidX and React Native

查看:34
本文介绍了使用 AndroidX 和 React Native 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将 AndroidX 集成到我的混合 React Native 项目中,但遇到了 Jetifier 无法在本地"项目上运行的问题.这导致我所有的 React Native 库仍然使用旧的支持库.我已将适当的行放入我的 gradle.properties 文件中:

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

这适用于任何远程库,但 React Native 将其所有库作为本地模块放在磁盘上.

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

我已经尝试了很多方法,但到目前为止我最好的解决方案是一个包安装后脚本,它基本上手动替换所有包并将库添加/删除到各种 gradle 脚本.

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?

推荐答案

尝试在安装后脚本中使用下面的 npm Jetifier 包

try using the npm Jetifier package below in a postinstall script

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

来自自述文件:

Make sure your app is AndroidX
npm install --save-dev jetifier
npx jetify (may take a while)
npx react-native run-android

这篇关于使用 AndroidX 和 React Native 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆