1.问题:
React Native开发Android,打包签名的APK没有问题,可以正常运行,但是直接在工程中通过命令行react-native run-android
,以开发模式运行程序,程序启动后报错:
React Native version mismatch.
JavaScript version: 0.54.3
Native version: 0.55.3
Make sure that you have rebuilt the native code. If the problem persists try clearing the Watchman and packager caches with `watchman watch-del-all && react-native start --reset-cache`.
reactConsoleErrorHandler
checkVersions
(anonymous function)
loadModuleImplementation
guardedLoadModule
_require
(anonymous function)
executeApplicationScript
(anonymous function)
regeneratorRuntime is not defined
handleException
handleError
reportFatalError
guardedLoadModule
_require
(anonymous function)
executeApplicationScript
(anonymous function)
Failed to print error:
原因不明。
试过将node_modules整体删除再安装,不好用。
这个问题到底是什么原因引起的,如何修复呢?
这个问题已经得到解决,参照stackoverflow上的问题:https://stackoverflow.com/que...
这个问题的原因就处在Android工程中
app/build.gradle
中,build.gradle
中对于 react-native库的版本的配置默认是这么写的:这个最后面的 “+” 表示的是使用最新的版本号。
也就是说,我们Android工程中,依赖的React native 的native代码版本号是使用网络上发布的最新版本。
这也是我们这个问题产生的根本原因。
按照上面链接中的问题的回答,进行如下修改:
再执行
react-native run-android
,一切恢复正常。真是个大坑,耽误了自己一上午的时间。补充:
报这个错误还有一种情况,那就是我们先用
react-native run-android
运行了其他的不同RN版本的工程,这个时候,如果我们不关闭其他运行中的RN工程的调试进程就在我们想要启动的工程下面运行react-native run-android
命令的话,也会在安装的 app中报这个错误,也就是对应 stack overflow 链接中的票数最多的回答。总结一下:
产生这个错误可能有两种情况:
第一种情况,也是比较常见的情况是:有其他不同RN版本号的工程以开发模式运行,这时如果我们以
react-native run-android
运行我们自己想要调试的工程的话,会报这个错误。第二种情况,可能相比第一种情况不常见,原因在于可能在我们的开发周期内,RN的Native版本库不一定会更新。第二种情况就是,我们在Android工程中配置的RN库版本与 JS工程中配置的RN库版本不一致。这种情况下只需将
android/app/build.gradle
下的RN库默认配置改为:问题即可解决。