【React Native】Unable to resolve module 'AccessibilityInfo'

今天研究React Native APP 开发,参考官网https://reactnative.cn/docs/getting-started.html

但是按照官方给出来的搭建方案创建了一个AwesomeProject后,执行 react-native run-android 安装Android APP后却是一屏大红幕报 Unable to resolve module ‘AccessibilityInfo’ 的异常,

 

This might be related to https://github.com/facebook/react-native/issues/4968
 
To resolve try the following:
 
  1. Clear watchman watches: `watchman watch-del-all`.
 
  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
 
  3. Reset Metro Bundler cache: `rm -rf $TMPDIR/react-*` or `npm start -- --reset-cache`.

各种尝试无果后,猜测可能是native版本问题,于是在网上找成功安装的版本。最后确定版本

react-native 0.55.4

react-native-cli 1.2.0

执行以下命令 写在react-native-cli

#卸载之前的版本
npm uninstall -g react-native-cli

#安装0.55.4版本react-native
npm install react-native@0.55.4

#安装1.2.0版本react-natice-cli
npm install -g react-native-cli@1.2.0

#初始化项目 一定要带上版本号(projectname:你的项目名称)
react-native init --version="0.55.4" projectname

项目初次创建花一点时间,耐心等待。进入你的项目目录 执行react-native run-android

出现如下问题

react-native version mismatch 

不要慌!其实就是编译版本不匹配

1、查看项目package.json 看react-native的版本

2、找到安装项目目录,android/app/build.gradle像这样在文件中强制React Native版本compile (“com.facebook.react:react-native:0.55.4”) { force = true }。更改0.55.4为您使用的版本。 

原始代码 compile "com.facebook.react:react-native:+" 这样会取最新版本,是导致JavaScript Version和Native Version不匹配的根源

3、再次执行react-native run-android就可以了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值