【React Native】Unable to resolve module 'AccessibilityInfo'

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/knockheart/article/details/81571586

今天研究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 [email protected]

#安装1.2.0版本react-natice-cli
npm install -g [email protected]

#初始化项目 一定要带上版本号(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就可以了。

猜你喜欢

转载自blog.csdn.net/knockheart/article/details/81571586
今日推荐