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

如何配置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 android command-line tool to list target Android platforms.
  • Android Studio 3.1 (and later) ships with a modernized SDK toolset that replaces the old android command with sdkmanager. The old android binary 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 android tool 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 android command (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 the tools subfolder inside this path contains the android executable.
  • 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_profile or source ~/.zshrc to 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, the android tool 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 android tool again.
  • If you plan to do long-term Android development, consider upgrading Unity to 2018.3 or later. These versions support the modern sdkmanager tool and have better compatibility with newer Android Studio releases.
  • If problems persist, try deleting your project's Library folder and reimporting the project to clear Unity's cached build settings.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 08:16:13