React Native Linux环境SDK路径错误求助:已装依赖仍编译失败
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.propertiesexists. 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
~/.bashrcfile with a text editor:
Add the two export lines from above at the end of the file. Save withnano ~/.bashrcCtrl+O, exit withCtrl+X, then apply the changes:source ~/.bashrc - For Zsh users: Edit
~/.zshrcinstead:
Add the same export lines, save, then run:nano ~/.zshrcsource ~/.zshrc
Step 3: Verify Your Setup
Let's confirm everything is working correctly:
- Run
echo $ANDROID_HOMEin 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.propertiesis 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

