如何将ANDROID_HOME指向/usr/local/android-sdk?React Native编译报错求助
Hey there, let's work through your React Native Android issues one by one:
1. Resolving the Missing Build Tools 25.0 Error
Even though your build.gradle specifies buildToolsVersion '26.0.1', the error about missing 25.0 likely comes from a dependency in your project that requires this specific build tool version. Here's how to install it:
- Open Android Studio, go to Tools > SDK Manager
- Switch to the SDK Tools tab
- Check the box that says Show Package Details (top-right corner)
- Scroll down to Android SDK Build-Tools, expand the list
- Find and check the
25.0version, then click Apply to install it
Once installed, try rebuilding your project again.
2. What Does "Point ANDROID_HOME to /usr/local/android-sdk" Mean?
ANDROID_HOME is an environment variable that tells tools like React Native, Gradle, and the Android build system where your Android SDK is installed on your computer. Setting it ensures these tools don't have to guess the SDK path, which avoids path-related errors.
How to Set It Up (Mac/Linux):
- Open your terminal and edit your shell configuration file (use
~/.bashrcfor Bash,~/.zshrcfor Zsh, depending on your shell) - Add these two lines to the file:
export ANDROID_HOME=/usr/local/android-sdk export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools - Save the file, then run this command to apply the changes immediately:
source ~/.zshrc # Or source ~/.bashrc if you use Bash - Verify it worked by running:
You should seeecho $ANDROID_HOME/usr/local/android-sdkprinted in the terminal.
3. Quick Check of Your build.gradle Configuration
Looking at your config:
android { compileSdkVersion 26 buildToolsVersion '26.0.1' defaultConfig { applicationId "xxxxxxxxxxxxx" minSdkVersion 19 targetSdkVersion 25 versionCode 1 versionName "1.0" multiDexEnabled true ndk { abiFilters 'armeabi-v7a', 'x86' } manifestPlaceholders = [ ..... ] } ... }
- Your
compileSdkVersionis 26, buttargetSdkVersionis 25. For better compatibility, consider updatingtargetSdkVersionto 26 (unless you have specific dependencies that require 25). This can help avoid version mismatch warnings. - The rest of the config looks solid (multiDex enabled, correct ABI filters) — no red flags there.
After completing these steps, restart Android Studio and try running your React Native Android project again.
内容的提问来源于stack exchange,提问作者Hugo

