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

Unity中Win32Exception报错:无法找到gradlew.bat文件求助

Unity Gradle未生成gradlew.bat文件问题解决

环境信息

  • 操作系统:Windows 11(最新稳定版)
  • 受影响Unity版本:
    • 2021.3.24f1
    • 2020.3.47f1
    • 2022.2.18f1

问题核心

Gradle仅生成了gradlew脚本,未生成Windows平台必需的gradlew.bat批处理文件,导致Unity的PlayServicesResolver执行时触发文件找不到的错误,怀疑与WSL或UNIX命令模拟工具(如Git Bash)的环境干扰有关。

完整错误日志

Win32Exception: ApplicationName='D:\CodingHub\Unity\TEST\Temp\PlayServicesResolverGradle\gradlew.bat', CommandLine='--daemon -b "D:\CodingHub\Unity\TEST\Temp\PlayServicesResolverGradle\PlayServicesResolver.scripts.download_artifacts.gradle" "-PANDROID_HOME=C:/Program Files/Unity/Hub/Editor/2020.3.47f1/Editor/Data/PlaybackEngines/AndroidPlayer\SDK" "-PTARGET_DIR=D:\CodingHub\Unity\TEST\Assets\Plugins\Android" "-PMAVEN_REPOS=https://android-sdk.is.com/;https://maven.google.com/" "-PPACKAGES_TO_COPY=com.ironsource.sdk:mediationsdk:7.2.5;com.google.android.gms:play-services-ads-identifier:17.0.0;com.google.android.gms:play-services-basement:17.2.1" "-PUSE_JETIFIER=1" "-PDATA_BINDING_VERSION=4.0.1"', CurrentDirectory='D:\CodingHub\Unity\TEST\Temp\PlayServicesResolverGradle', Native error= The system cannot find the file specified.

System.Diagnostics.Process.StartWithCreateProcess (System.Diagnostics.ProcessStartInfo startInfo) (at <1e13855442cf491a8b11d7de866cc016>:0)
System.Diagnostics.Process.Start () (at <1e13855442cf491a8b11d7de866cc016>:0)
(wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
GooglePlayServices.CommandLine.RunViaShell (System.String toolPath, System.String arguments, System.String workingDirectory, System.Collections.Generic.Dictionary`2[TKey,TValue] envVars, GooglePlayServices.CommandLine+IOHandler ioHandler, System.Boolean useShellExecution, System.Boolean stdoutRedirectionInShellMode, System.Boolean setLangInShellMode) (at /Users/chkuang/Workspace/git/unity-jar-resolver/source/AndroidResolver/src/CommandLine.cs:638)
GooglePlayServices.CommandLine.Run (System.String toolPath, System.String arguments, System.String workingDirectory, System.Collections.Generic.Dictionary`2[TKey,TValue] envVars, GooglePlayServices.CommandLine+IOHandler ioHandler) (at /Users/chkuang/Workspace/git/unity-jar-resolver/source/AndroidResolver/src/CommandLine.cs:510)
GooglePlayServices.CommandLine+<RunAsync>c__AnonStorey0.<>m__0 () (at /Users/chkuang/Workspace/git/unity-jar-resolver/source/AndroidResolver/src/CommandLine.cs:135)
System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Threading.ThreadHelper.ThreadStart () (at <695d1cc93cca45069c528c15c9fdd749>:0)
UnityEngine.<>c:<RegisterUECatcher>b__0_0(Object, UnhandledExceptionEventArgs)

已尝试无效操作

  • 配置自定义SDK、NDK、JDK
  • 使用scoop安装的Gradle替代默认版本
  • 反复重装卸载相关组件

可行解决方案

1. 手动生成gradlew.bat

进入缺失文件的目录(D:\CodingHub\Unity\TEST\Temp\PlayServicesResolverGradle),打开命令提示符执行:

gradle wrapper --gradle-version <对应Unity的Gradle版本>

版本号可在Unity编辑器的Project Settings > Player > Android > Publishing Settings > Build > Gradle Version中获取。执行完成后重试构建。

2. 调整环境变量优先级

WSL或UNIX模拟工具的路径可能抢占了Windows原生命令的优先级,导致Gradle生成UNIX脚本:

  • 打开系统环境变量设置,找到PATH变量
  • 将C:\Windows\System32移至PATH列表最顶端
  • 重启Unity后重试

3. 强制Gradle生成Windows脚本

在项目的Assets/Plugins/Android/gradle.properties文件中添加以下配置(文件不存在则手动创建):

org.gradle.wrapper.windows=true

保存后重新触发PlayServicesResolver的依赖下载流程。

4. 清理Unity缓存文件

关闭Unity编辑器,删除项目根目录下的Temp和Library文件夹,重新打开项目等待资源导入完成后,再执行相关操作。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 10:37:00