react-native-cli运行Android项目失败求助(Ubuntu 16.04环境)
Hey there! Let's tackle this React Native run-android issue step by step. Since your Android Studio project with API level 23 works perfectly, the problem is likely tied to React Native's specific setup rather than your core Android development environment. Here are the most common fixes to try out:
First, make sure your Android-related environment variables are correctly set up for React Native:
- Open your terminal and run these commands to check:
echo $ANDROID_HOME echo $PATH - Confirm
ANDROID_HOMEpoints to your Android SDK directory (usually~/Android/Sdk), and yourPATHincludes$ANDROID_HOME/toolsand$ANDROID_HOME/platform-tools. - If the variables are missing or incorrect, edit your shell configuration file (either
~/.bashrcor~/.zshrc, depending on which shell you use) and add these lines:export ANDROID_HOME=$HOME/Android/Sdk export PATH=$PATH:$ANDROID_HOME/tools export PATH=$PATH:$ANDROID_HOME/platform-tools - Run
source ~/.bashrc(or the corresponding file) to apply the changes immediately.
Ensure your React Native project's Android configuration matches the working API level 23 setup:
- Open
android/build.gradlein your project and check thatcompileSdkVersionandtargetSdkVersionare set to 23. - Then open
android/app/build.gradleand confirmminSdkVersionis set to a value that's compatible (like 21 or directly 23).
Cached files often cause unexpected build errors. Try clearing them:
- Reset React Native's cache first:
npx react-native start --reset-cache - Navigate to the Android directory and clean the Android project:
cd android && ./gradlew clean - Go back to your project root and re-run the command:
npx react-native run-android
Make sure your target device or emulator is properly recognized:
- Run
adb devicesto list connected devices. If you're using an emulator, ensure it's created with API level 23 (matching your working Android Studio project). - For physical devices, double-check that USB debugging is enabled and Ubuntu has detected the device (you can use
lsusbto verify).
If none of the above steps work, run the command with verbose mode to get specific error details:
npx react-native run-android --verbose
The detailed logs will help pinpoint exactly where the build is failing—whether it's a dependency conflict, Gradle version mismatch, or NDK-related issue.
内容的提问来源于stack exchange,提问作者gayashanbc

