如何配置Unity 2017.4适配Android并解决Mac下构建失败问题
Hey there, let's dig into why this build failure keeps happening and fix it properly on your Mac!
Root Cause Breakdown
The core issue boils down to compatibility gaps between Unity 2017.4 and Android Studio 3.1's default SDK setup:
- Unity 2017.4 is a relatively older version that relies on the deprecated
androidcommand-line tool to list target Android platforms. - Android Studio 3.1 (and later) ships with a modernized SDK toolset that replaces the old
androidcommand withsdkmanager. The oldandroidbinary is no longer included in default SDK installations. - Even if you've set the SDK path correctly in Unity's Preferences, Unity might fail to locate the required
androidtool if your Mac's environment variables aren't configured to expose it, or if the tool simply isn't installed.
Elegant Fixes for Mac Environment
1. Install the Deprecated Android SDK Tools Unity Needs
First, we need to add back the old android tool that Unity 2017.4 depends on:
- Open Android Studio → Go to
Tools > SDK Manager - Switch to the SDK Tools tab
- Check the box for Show Package Details (bottom-left corner)
- Expand the Android SDK Tools section, then select an older version that includes the
androidcommand (version 25.2.5 is a safe bet for Unity 2017.4) - Also ensure you have compatible components installed:
- Android SDK Platform-tools (latest compatible version)
- Android SDK Build-tools 26.0.2 (tested to work well with Unity 2017.4)
- A matching Android Platform (e.g., Android 8.0 API 26)
- Click Apply to install these components.
2. Configure Unity and Mac Environment Variables
Option A: Directly Set Paths in Unity
- Launch Unity → Go to
Edit > Preferences > External Tools - Verify that Android SDK Location points to your SDK root (usually
~/Library/Android/sdk). Double-check that thetoolssubfolder inside this path contains theandroidexecutable. - For JDK Location, use JDK 8 (Unity 2017.4 has known issues with newer JDK versions; you can download JDK 8 separately or use the one bundled with an older Android Studio version if needed).
Option B: Set System Environment Variables (Ensure Unity Reads Them)
Sometimes Unity doesn't pick up the SDK path even if set in Preferences, so we'll set it globally:
- If you use Bash: Open Terminal and edit your profile file with
open ~/.bash_profile - If you use Zsh (default on newer Macs): Edit
open ~/.zshrc - Add these lines to the file:
export ANDROID_HOME="$HOME/Library/Android/sdk" export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH" - Save the file, then run
source ~/.bash_profileorsource ~/.zshrcto apply changes immediately. - Restart Unity so it picks up the new environment variables.
3. Verify the Fix
- Open Terminal and run
android list target. If this command outputs a list of installed Android platforms, theandroidtool is working correctly. - Go back to Unity and try rebuilding your Android project. The "Unable to list target platforms" error should be gone.
Extra Tips to Avoid Future Issues
- Don't update the Android SDK Tools to the latest version once you've installed the compatible old one—this will remove the
androidtool again. - If you plan to do long-term Android development, consider upgrading Unity to 2018.3 or later. These versions support the modern
sdkmanagertool and have better compatibility with newer Android Studio releases. - If problems persist, try deleting your project's
Libraryfolder and reimporting the project to clear Unity's cached build settings.
内容的提问来源于stack exchange,提问作者German
相关产品推荐
相关产品推荐

