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

React Native Linux环境SDK路径错误求助:已装依赖仍编译失败

Fixing "SDK location not found" Error in React Native

Hey there, let's work through this SDK path issue you're facing with your React Native project. The error makes it clear Gradle can't locate your Android SDK, even though you know the path is /home/rojib/Android/Sdk. Let's go through two reliable fixes, plus some checks to make sure everything sticks.

Step 1: Create or Update the local.properties File

Gradle first looks for the SDK path in your project's android directory via the local.properties file. Chances are this file is missing (it's often excluded from version control) or has an incorrect path:

  • Navigate to your project's android folder:
    cd /home/rojib/Documents/react/lat3/React-Native-Sample/android
    
  • Check if local.properties exists. If not, create it with:
    touch local.properties
    
  • Open the file and add this line (match your SDK path exactly):
    sdk.dir=/home/rojib/Android/Sdk
    
  • Save the file, then try running your project again with npx react-native run-android

Step 2: Set the ANDROID_HOME Environment Variable

If the first step doesn't resolve the issue, setting a system-wide environment variable will ensure Gradle can find the SDK no matter which project you're working on:

Temporary Fix (current terminal session only)

Run these commands in your terminal right now:

export ANDROID_HOME=/home/rojib/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Then re-run your React Native project command.

Permanent Fix (persists across terminal sessions)

This ensures the variable is set every time you open a terminal:

  • For Bash users: Open your ~/.bashrc file with a text editor:
    nano ~/.bashrc
    
    Add the two export lines from above at the end of the file. Save with Ctrl+O, exit with Ctrl+X, then apply the changes:
    source ~/.bashrc
    
  • For Zsh users: Edit ~/.zshrc instead:
    nano ~/.zshrc
    
    Add the same export lines, save, then run:
    source ~/.zshrc
    

Step 3: Verify Your Setup

Let's confirm everything is working correctly:

  • Run echo $ANDROID_HOME in your terminal — it should output /home/rojib/Android/Sdk
  • Run adb devices — this should list your connected physical device or running emulator (proof that the SDK tools are accessible)

Quick Additional Checks

  • Double-check that your SDK directory has proper read/write permissions for your user. You can verify this with:
    ls -ld /home/rojib/Android/Sdk
    
  • If you pulled this project from Git, remember that local.properties is usually in .gitignore, so you'll need to create it manually (which we did in Step 1) — it won't be included in the repository.

内容的提问来源于stack exchange,提问作者rojib

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:13:59