react native 出现程序包com.facebook.react不存在

错误: 程序包com.facebook.react.bridge不存在 import com.facebook.react.bridge.ReactApplicationContext;

今天在通过android studio 编译react-native 项目的时候,莫名出现com.facebook.react下的文件不存在,部分缺失如图:

如:程序包com.facebook.react不存在、 程序包com.facebook.react.bridge不存在、程序包com.facebook.react.uimanager不存在

项目中react-native引入是通过:

implementation 'com.facebook.react:react-native:+'

1

解决办法:

方法一:react-native版本低于0.63,在 android\build.gradle 添加如下内容:

def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())

allprojects {
    configurations.all {
        resolutionStrategy {
            // Remove this override in 0.65+, as a proper fix is included in react-native itself.
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
    }
    
}

添加这段代码意思是获取到当前使用的 react-native 版本,然后把所有依赖项目的 rn 都覆盖成这个版本。

在我自己的项目,刚开始是用在每个build.gradle,引用到implementation ‘com.facebook.react:react-native:+’,都直接写死版本号:implementation ‘com.facebook.react:react-native:0.52.0’

方法二:react-native版本大于0.63,根据官网issue(Android build failures happening since Nov 4th 2022 · Issue #35210)里找到对应的热更新补丁,更新 package.json 内容,重新 yarn install,然后 cd android && ./gradlew clean 清理缓存,之后应该就恢复正常了

————————————————

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值