Unity Android构建报错求助:Gradle依赖失败与SDK管理器问题
Hey Matt, let's work through these two frustrating issues with your Unity Android project—they’re likely tied to outdated resolver tools or misconfigured SDK settings. Here’s how to fix each one step by step:
错误1:Gradle failed to fetch dependencies(输入字符串"0-alpha1")
This error pops up because the Play Services Resolver is trying to pull an unstable alpha version of a dependency, which breaks the Gradle evaluation. Here’s how to fix it:
Update the External Dependency Manager (formerly Play Services Resolver)
Open Unity’sWindow > Package Manager, search for "External Dependency Manager for Unity" (it replaced the old Play Services Resolver), and install/update it to the latest stable version. If it’s not in the Package Manager, grab it from the Unity Asset Store—this is the most common fix for version-related parsing errors.Lock dependency versions to stable releases
Go toWindow > Google > Play Services Resolver > Android Resolver > Settings. In the "Dependency Version" section, replace the+wildcard in your packages with specific stable versions. For example:com.google.android.gms:play-services-gcm:17.0.0com.google.android.gms:play-services-location:21.0.1com.android.support:customtabs:28.0.0com.android.support:support-v4:28.0.0
This prevents the resolver from pulling untested alpha builds like "0-alpha1".
Clear cached Gradle files
Delete theTemp/PlayServicesResolverGradlefolder in your Unity project, then clear your system Gradle cache (usually located atC:\Users\<YourUsername>\.gradle\caches). Restart Unity and let the resolver re-download dependencies fresh.
错误2:Unable to find Android SDK manager tool & missing M2 repositories
This issue happens when Unity can’t locate the SDK manager tool, or the required Google/Android M2 repositories aren’t installed properly. Try these fixes:
Verify Unity’s SDK path configuration
OpenEdit > Preferences > External Toolsin Unity. Double-check that the Android SDK path points to your correct SDK directory (e.g.,F:/Programs/AndroidSDK)—make sure there are no spaces or special characters in the path, which can break tool detection.Manually install missing repositories via Android Studio
Open Android Studio, go toTools > SDK Manager, switch to theSDK Toolstab, and check "Show Package Details". Under theExtrassection, find and install:Google Repository(latest stable version)Android Repository(latest stable version)
Once installed, go back to Unity and runWindow > Google > Play Services Resolver > Android Resolver > Resolveto re-detect the repositories.
Fix SDK Manager tool accessibility
Ensure you have theCommand-line Toolsinstalled in Android Studio’s SDK Manager (under SDK Tools). Add thecmdline-tools/binfolder from your SDK directory (e.g.,F:/Programs/AndroidSDK/cmdline-tools/latest/bin) to your system’sPATHenvironment variable. This lets Unity find thesdkmanagercommand properly.Reset the resolver’s state
Go toWindow > Google > Play Services Resolver > Android Resolver > Reset Resolverto clear any cached SDK detection data, then re-run the resolve process.
补充:关于游戏运行缓慢的问题
While you think it’s unrelated to the errors, unresolved dependency issues can sometimes cause hidden overhead (like failed lazy loading or fallback logic). Once you fix the two core errors, use Unity’s Profiler (Window > Analysis > Profiler) to check for performance bottlenecks—things like excessive draw calls, unoptimized textures, or inefficient script logic are common culprits for slow Android builds.
内容的提问来源于stack exchange,提问作者MOrlando616

