Android构建时无法列出目标平台(Unity 2017.3.1f1)
Hey there, let’s work through this frustrating build issue together. Since you’ve already tried swapping to JDK 8 and older SDK tools without luck, let’s dive into more targeted steps to get your Release build over the line:
Validate your SDK path (no sneaky whitespace allowed!)
Spaces or special characters in your SDK path often break the build tool’s ability to resolve directories. For example, avoid paths likeC:\Program Files\Android\SDK—instead use something likeC:\AndroidSDK. Double-check that this path matches exactly where your SDK is installed, then test it by runningsdkmanager --listin your SDK’scmdline-tools/latest/binfolder. If this command throws an error, your path is definitely the problem.Install the exact target SDK version your project requires
Open your project’s build config (likebuild.gradleor Unity’s Player Settings) and note the target SDK version (e.g., 33). Head to Android Studio’s SDK Manager, go to the "SDK Platforms" tab, and make sure that specific version is checked and fully installed. Build tools can be picky about matching the target platform exactly—don’t assume a newer version will work as a replacement.Refresh your SDK Command-line Tools
Corrupted or outdated command-line tools are a common culprit. In SDK Manager, go to "SDK Tools", check "Show Package Details", then find "Command-line Tools" and install the latest stable release (skip canary builds). After installing, delete any oldcmdline-toolsfolders in your SDK directory to eliminate conflicts.Double-check your environment variables
EnsureANDROID_HOME(orANDROID_SDK_ROOT) is set to your SDK’s root directory in your system’s environment variables. Also add%ANDROID_HOME%\cmdline-tools\latest\binand%ANDROID_HOME%\platform-toolsto yourPATH. Test this by opening a new command prompt and runningadb --versionandsdkmanager --version—both should run without errors if your variables are set correctly.Wipe cached build files and rebuild from scratch
Stale cached files can cause weird build conflicts. Delete thebuildfolder in your Android project (or in Unity, useFile > Build Settings > Clean), then delete the.gradlefolder in your project root. Restart your IDE/Unity and try the Release build again—fresh starts fix more issues than you’d think.Fix permission issues on your SDK directory
On Windows, right-click your SDK folder, go to "Properties > Security > Edit", and grant your user account full read/write permissions. On macOS or Linux, runchmod -R 755 /path/to/android-sdkto ensure the build tool can access all necessary files.
If none of these steps work, try running the build via the command line instead of the GUI. This will often output more detailed error logs that can point to the exact problem (e.g., missing packages, corrupted files) that the standard error message hides.
内容的提问来源于stack exchange,提问作者Peter Morris

