![](/img/trans.png)
[英]React Native version mismatch Js Version 0.50.4 Native Version 0.62.2
[英]React Native version Mismatch - Native version: 0.59.5
我在 Android 模擬器上收到此錯誤:
React Native 版本不匹配:
Javascript 版本:0.58.5
本機版本:0.59.5
我已經升級了 React Native、模塊、Android Studio 和幾乎所有我能升級的東西。 在 iOS 上一切正常,這只發生在 Android 上。 構建成功
包.json
{
"name": "MyProject",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"@react-native-community/async-storage": "^1.3.3",
"latlon-geohash": "^1.1.0",
"react": "16.8.3",
"react-native": "0.59.5",
"react-native-firebase": "^5.2.3",
"react-native-gesture-handler": "^1.0.16",
"react-native-keyboard-aware-scroll-view": "^0.8.0",
"react-native-linear-gradient": "^2.5.3",
"react-native-maps": "^0.24.2",
"react-native-vector-icons": "^6.4.2",
"react-navigation": "^3.3.2",
"react-redux": "^6.0.1",
"redux": "^4.0.1"
},
"devDependencies": {
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "24.1.0",
"jest": "24.1.0",
"metro-react-native-babel-preset": "0.52.0",
"react-test-renderer": "16.6.3"
},
"jest": {
"preset": "react-native"
}
}
構建.gradle
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
googlePlayServicesVersion = "15.0.1"
androidMapsUtilsVersion = "0.5+"
}
repositories {
google()
//mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
/*
task wrapper(type: Wrapper) {
gradleVersion = '4.7'
distributionUrl = distributionUrl.replace("bin", "all")
}*/
dependencies {
implementation project(':react-native-firebase')
implementation project(':react-native-gesture-handler')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation project(':react-native-linear-gradient')
implementation project(':react-native-maps')
implementation "com.google.android.gms:play-services-base:16.0.1"
implementation project(':@react-native-community_async-storage')
implementation ("com.google.firebase:firebase-core:16.0.7") {
exclude group: 'com.google.android.gms'
}
implementation ("com.google.firebase:firebase-auth:16.1.0") {
exclude group: 'com.google.android.gms'
}
implementation ("com.google.firebase:firebase-database:16.0.6") {
exclude group: 'com.google.android.gms'
}
}
我試過關閉所有終端,yarn install,創建新的 android 設備。 我猜它與 Package.json 中 React Native 的實際版本有關,但它是 0.59.5,當我搜索整個項目時,我無法在任何地方找到對 0.58.5 的任何引用。
我在 github 論壇的幫助下解決了這個問題。 在我的案例中,這個錯誤是由於在模擬器中安裝了 Android 9 引起的。 安裝 Android 版本 8 的新設備解決了這個問題。
關閉所有終端和 IDE,然后再次啟動它。 它會起作用
確保package.json
中的 RN 版本與android/app/build.gradle
中的相同,它應該如下所示:
在 package.json 中
"react-native": "0.59.5",
在android/app/build.gradle
implementation ("com.facebook.react:react-native:0.59.5") { force = true }
編輯:您能否也檢查一下打包器和模擬器/設備是否在同一個網絡中,並且 JS 包是從正確的位置獲取的? 看起來您的應用程序在構建時沒有得到更新,它停留在舊代碼中。
嘗試以下:
包.json
"react": "16.8.6",
"react-native": "0.60.4",
"react-native-maps": "0.25.0",
構建.gradle:
googlePlayServicesVersion = "15.0.1"
androidMapsUtilsVersion = "0.5+"
我有workdir/android/app/src/main/assets/index.android.bundle
從我使用舊 RN 的另一個分支的上一個構建中留下。
運行react-native bundle --platform android --dev true --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
為我修復了它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.