使用 Gradle 编译时出错(找不到下载的依赖项)

Error when compiling with Gradle (can't find downloaded dependencies)

我开发了一个应用程序生成系统,通过命令行Gradle编译命令重新生成应用程序。

在我的 Windows Server 2008 中,我在更新到最新的 Gradle 版本和 Gradle 插件版本后遇到了问题。

编译时出现以下错误:

C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\appcompat-v7-25.0.0.aar\e93435c34d5cae8b6677dcef529711a5\res\drawable-xxhdpi-v4\abc_text_select_handle_middle_mtrl_light.png: error: file not found.

C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\appcompat-v7-25.0.0.aar\e93435c34d5cae8b6677dcef529711a5\res\drawable\abc_btn_colored_material.xml: error: file not found.

C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\appcompat-v7-25.0.0.aar\e93435c34d5cae8b6677dcef529711a5\res\drawable-hdpi-v4\abc_textfield_search_default_mtrl_alpha.9.png: error: file not found.

and a lot more of errors like those...

我不确定为什么会收到此错误,因为文件已正确下载并且正确位于该方向。

它的路径长度为 204 个字符,因此据推测它没有超过 NTFS Windows 文件系统上 255 个路径字符的限制。

可以更改 Gradle 下载其缓存依赖项的位置吗?这个问题是这个还是其他原因引起的?

最后我解决了将windows中的环境变量GRADLE_USER_HOME设置为c:/gradle-cache

所以肯定与文件路径长度有关

我在 windows jenkins

中遇到了同样的错误

我解决了这个错误。

gradle assembleDebug -g C:\gradle-cache

-g:

gradle -h

-g, --gradle-user-home    Specifies the gradle user home directory

路径长度导致失败。

我定义了

"-Dorg.gradle.user.home=%GRADLE_USER_HOME%"

在 gradle 运行 参数中,它解决了问题。