You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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:

1. Verify Environment Variable Configuration

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_HOME points to your Android SDK directory (usually ~/Android/Sdk), and your PATH includes $ANDROID_HOME/tools and $ANDROID_HOME/platform-tools.
  • If the variables are missing or incorrect, edit your shell configuration file (either ~/.bashrc or ~/.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.
2. Align SDK Versions in React Native Project

Ensure your React Native project's Android configuration matches the working API level 23 setup:

  • Open android/build.gradle in your project and check that compileSdkVersion and targetSdkVersion are set to 23.
  • Then open android/app/build.gradle and confirm minSdkVersion is set to a value that's compatible (like 21 or directly 23).
3. Clear Caches for React Native and Android

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
    
4. Check Device/Emulator Connection

Make sure your target device or emulator is properly recognized:

  • Run adb devices to 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 lsusb to verify).
5. Get Detailed Error Logs

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:36:51