求助:React Native开发出现"未能找到哈希字符串为android-23的目标"错误
Hey there fellow Iranian dev! I totally get how frustrating this error is—especially when you’re just starting out with React Native, and most Stack Overflow answers don’t account for the network barriers we deal with here. Let’s break down the fix tailored to our situation.
First: Understand the Problem
This error pops up because your React Native project is configured to target Android 6.0 (Marshmallow, codename android-23), but your Android Studio environment doesn’t have this SDK version installed. The usual online download method via Google’s servers often doesn’t work for us, so we need offline or alternative workarounds.
Quick Fix: Switch to a Different SDK Version (If Possible)
If your project doesn’t strictly require android-23 (most modern apps don’t), this is the easiest way out:
- Open your project’s
android/app/build.gradlefile - Look for these lines:
compileSdkVersion 23 targetSdkVersion 23 - Change the numbers to an SDK version you already have installed (check Android Studio’s SDK Manager for available versions—30 or 33 are safe, widely supported choices)
- Sync your project with Gradle (click the "Sync Now" prompt that appears)
If You Must Use Android-23 (Offline Solution)
If your project or dependencies require android-23, here’s how to install it without relying on Google’s servers:
- Get the Android-23 SDK Package Offline
- Ask a fellow developer to share the
android-23folder from their SDK’splatformsdirectory, or download a trusted offline copy of the SDK Platform 6.0 (Marshmallow)
- Ask a fellow developer to share the
- Place the Folder in Your SDK Directory
- Locate your Android SDK path:
- Mac:
~/Library/Android/sdk/platforms - Windows:
C:\Users\<YourUsername>\AppData\Local\Android\Sdk\platforms - Linux:
/home/<YourUsername>/Android/Sdk/platforms
- Mac:
- Paste the
android-23folder directly into this directory
- Locate your Android SDK path:
- Let Android Studio Recognize It
- Open Android Studio, go to
File > Settings > Appearance & Behavior > System Settings > Android SDK - Navigate to the
SDK Platformstab, click the "Refresh" icon in the top-right corner - You should see "Android 6.0 (Marshmallow)" show up—check the box next to it, then click "Apply" to confirm
- Open Android Studio, go to
- Install Corresponding Build Tools
- You’ll also need Build Tools version 23.0.3 (the matching version for
android-23) - Repeat the offline process: get the
23.0.3folder, paste it into your SDK’sbuild-toolsdirectory - Go to the
SDK Toolstab in Android Studio’s SDK Manager, check the box for "Android SDK Build-Tools 23.0.3", then click "Apply"
- You’ll also need Build Tools version 23.0.3 (the matching version for
Final Checks
- Double-check that your
local.propertiesfile (in theandroidfolder of your project) has the correctsdk.dirpath pointing to your SDK installation directory - Clean and rebuild your project to ensure changes take effect:
- Mac/Linux: Run
cd android && ./gradlew cleanin your terminal - Windows: Run
cd android && gradlew cleanin Command Prompt or PowerShell
- Mac/Linux: Run
- Try running your React Native app again
内容的提问来源于stack exchange,提问作者mohammadavood

