React Native版本不匹配(JS V:0.49.3 RN V:0.59.9)问题求助
Hey there! I totally get how frustrating this is—iOS runs fine, you can build an APK, but debugging mode via react-native run-android throws that version mismatch error. Let's walk through targeted fixes since the usual "close terminals" and basic cache resets didn't work:
Step 1: Wipe All Metro & Project Caches Completely
Metro Bundler and watchman can hold onto old cached data that doesn't clear with a simple reset. Run these commands in your project root:
- Stop any running Metro or React Native processes first (check your task manager if you're unsure!)
watchman watch-del-all(clears watchman's file watch cache)rm -rf node_modulesnpm install(oryarn installif you use yarn)rm -rf $TMPDIR/react-*rm -rf $TMPDIR/metro-*npx react-native start --reset-cache(start Metro with a full cache reset)
Step 2: Verify Android Project RN Version Configs
Sometimes the Android Gradle files don't sync properly with your package.json version. Double-check these files:
- Open
android/app/build.gradle: Look for the lineimplementation "com.facebook.react:react-native:+". Replace the+with your exact RN version0.59.9to avoid Gradle pulling an outdated version. - Check
android/build.gradle: Ensure thebuildscriptandallprojectssections don't have hardcoded references to0.49.3anywhere.
Step 3: Clean Android Gradle Cache
Gradle's cache is a common culprit for version mismatches on Android. Run:
cd android && ./gradlew clean(usegradlew cleanon Windows)- Optionally, delete the
.gradlefolder inside your project'sandroiddirectory, or even the global Gradle cache at~/.gradle/caches(note: this clears cache for all your Gradle projects, but can fix stubborn issues)
Step 4: Delete Old Android Bundle Files
If an outdated debug bundle is lingering, it can cause version conflicts:
- Navigate to
android/app/src/main/assetsand delete any existingindex.android.bundleorindex.bundlefiles. - Generate a fresh debug bundle with:
npx 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/
Step 5: Check Node Version Compatibility
React Native 0.59.9 works best with Node.js versions 8.x to 10.x. If you're using a newer Node version, it might cause dependency or packaging issues:
- Use a version manager like
nvmto switch to a compatible version (e.g.,nvm install 10.24.1thennvm use 10.24.1) - Reinstall your dependencies after switching Node versions
Step 6: Re-Run the Project
Once all the above steps are done, try running:
npx react-native run-android --reset-cache
Or start Metro first with npx react-native start --reset-cache, then run npx react-native run-android in a separate terminal.
A quick note on why iOS works: iOS uses CocoaPods for dependency management, which tends to sync versions more reliably than Android's Gradle. Plus, iOS's cache system is isolated from Android's, so the old version data doesn't carry over.
内容的提问来源于stack exchange,提问作者SmoggeR_js

