React Native Android项目运行报错:NDK缺失问题求助
Hey there, let's tackle that NDK missing error you're facing with your React Native Android project! Even with your Android and Java system variables set up correctly, this is a super common hiccup—here's how to fix it step by step:
Step 1: Install the Correct NDK Version via Android Studio
Different React Native versions require specific NDK versions (for example, RN 0.70+ needs NDK 25.1.8937393—double-check your RN docs for the exact version you need):
- Open Android Studio, go to Settings (Windows/Linux: File > Settings; Mac: Android Studio > Settings)
- Navigate to
Appearance & Behavior > System Settings > Android SDK - Switch to the SDK Tools tab, then check the
Show Package Detailsbox at the bottom-right - Find
NDK (Side by side), expand it, and check the box next to your required NDK version - Click Apply to start the installation
Step 2: Point Your Project to the Installed NDK
Your project might not automatically detect the NDK even after installation—let's set it explicitly:
- Go to your React Native project's root folder, open (or create if missing) the
android/local.propertiesfile - Add this line, replacing the path with your actual NDK installation path:
# Windows example ndk.dir=C\:\\Users\\YourUsername\\AppData\\Local\\Android\\Sdk\\ndk\\25.1.8937393 # Mac/Linux example ndk.dir=/Users/YourUsername/Library/Android/sdk/ndk/25.1.8937393 - Make sure to escape backslashes on Windows, or use forward slashes instead
Step 3: Lock the NDK Version in Gradle (Optional but Recommended)
To avoid version mismatches later, hardcode the NDK version in your project's gradle config:
- Open
android/build.gradleand look for theextblock. Add or update thendkVersionline:ext { buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 ndkVersion = "25.1.8937393" // Match the version you installed } - Click the Sync Now button in Android Studio to apply the changes
Step 4: Clean Cache and Re-run
Old cache can sometimes cause lingering issues, so let's wipe it and restart:
- Run this command to reset React Native's cache:
npx react-native start --reset-cache - Then re-launch your Android project:
npx react-native run-android
Quick Bonus: Install NDK via Command Line
If you prefer using the terminal instead of Android Studio, you can use the sdkmanager tool (make sure it's in your system PATH):
sdkmanager --install "ndk;25.1.8937393"
内容的提问来源于stack exchange,提问作者Sathya Raj

