当我初始化一个新项目,然后启动Xcode模拟器时,得到以下消息:

React-Native版本不匹配 Javascript版本0.50.1 本机版本:0.50.0 确保您已经重新构建了本机代码. ...

有谁知道这是怎么回事能帮帮我吗?


当前回答

所有那些关于改变版本以适应我的错误的答案。

这个错误没有告诉您这个版本来自哪里。在所有文件中搜索,我发现只有1个地方定义了javascript版本: 问题是这个包(\android\app\src\main\assets\index.android.bundle)需要重新生成,因为它包含的版本比安装的包要旧。

为了重新生成该文件,我必须运行以下命令:

react-native bundle --platform android --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

因为我已经升级了我的react-native,所以运行这个命令给了我一些需要解决的错误(主要是安装新的依赖项)。

清理缓存,在android studio中重新加载,重新加载react,重新加载终端,创建一个新项目并传输文件,运行watchman,所有这些都不能工作,因为特定的bundle文件恰好在Git repo中被跟踪。

其他回答

我试图从WebStorm中构建和运行一个React Native应用程序,然后遇到了这个问题。对我来说,简单的解决方案是:

watchman watch-del-all

在macOS上,如果watchman还没有安装,请使用Homebrew安装:

brew install watchman

这个答案发表于2020年, 在3个步骤中修复此错误:

第一步:我改变了expo在package中的值。Json文件到最新支持的版本,根据博览会文档(访问这里)。

第二步:我将app.json文件中的sdkVersion的值更改为package.json中expo的值。(与上一步数量相等)。

第三步:我在包中改变了react-native的值。根据expo文档(请访问这里),将json文件更改为与React Native Version相同的值。

现在你可以出发了。

使用NPM install来安装指定版本的依赖项,然后NPM开始运行项目

I've never seen this error before, but whenever I can't get Xcode and React-Native to play well together, I do a couple of things. Check what version of Xcode I'm working with. If it needs to be updated, I update it. Then clearing watchman and the cache are the second place I go. I don't use the reset cache command. It always says that I need to verify the cache, so I skip that (you can do it though, I just get confused). I use rm -rf $TMPDIR/react-* to get rid of any cached builds. If that doesn't work, I try to build the app in Xcode, then work my way from there, to build it with react-native run-ios. With this error message, it seems you might start by trying to build it with Xcode. Hope that helps...let me know your progress with it. Good luck! (Also, you could update to RN 0.51 as another attempt to get your versions synced.)

我正在使用物理设备,在我的情况下,这解决了问题:

卸载应用程序 Lsof -i:8081 kill -9 PID 重新构建应用程序(react-native run-android或react-native run-ios)

如果你用create-react-native-app创建react-native-app。你应该有一个app.json (expo)。还有一个包裹。Json文件,检查世博版本是否匹配并相应更改。例如,在我的案例中,问题是在app.json文件中,我有一个25.0.0版本的expo sdkVersion属性,我将其更改为23.0.0,一切正常工作。

package.json:

"dependencies": {
    "expo": "^23.0.4",
    "react": "16.0.0",
    "react-native": "^0.50.4"
  }

app.json:

{
  "expo": {
    "sdkVersion": "23.0.0" // before was 25.0.0
  }
}