问题描述
我有一个Hudson构建作业,由于错误而失败
I have a Hudson build job that's failing with the error
Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details
在日志中,很多行是这样的:
and in the logs, lots of lines like this:
C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\appcompat-v7-26.1.0.aar\3bbc697d357b69b5ea5f78a35f99a514\res\color\abc_hint_foreground_material_dark.xml: error: file not found.
我发现了一些关于AAPT2错误的问题,例如和,但是他们似乎没有解决办法.
I've found a few questions on AAPT2 errors like this, for example this and this but they don't seem to have a fix.
那为什么构建失败了?
推荐答案
根据第一个链接的问题,禁用AAPT2似乎是个坏主意,因为将来可能会删除AAPT.
As per the first linked question, disabling AAPT2 seems like a bad idea, as AAPT might be removed at some point in the future.
第二个链接的问题至少给出了一个线索,被接受的答案是该gradle版本不处理.gradle缓存路径中的非ASCII字符.但是在我们的情况下,正在记录的缓存路径中没有任何非ASCII字符.
The second linked question at least gives a clue, with the accepted answer there being that that version of gradle doesn't handle non-ASCII characters in the .gradle cache path. But in our case, there aren't any non-ASCII characters in the cache path being logged.
实际上,gradle在日志中寻找C:\Windows\System32\config\systemprofile\.gradle
内部的缓存,该缓存只能通过管理员权限访问.不是我们想要缓存库的地方.
In fact, from the logs, gradle is looking for the cache inside C:\Windows\System32\config\systemprofile\.gradle
, which is only accessible with admin privileges. Not somewhere we want to be caching libraries.
此答案以及在gradle论坛上的帖子是导致我进入解决方案.短版本是默认情况下,gradle在用户区域中缓存下载的库,并且似乎有一个错误,它将错误地确定用户的主目录.这导致gradle缓存被放置在它实际上不应该放置的地方.
This answer, along with this post on the gradle forums are what led me to the solution. Short version is, by default gradle caches downloaded libraries in the user area, and there seems to be a bug in Java where it will incorrectly determine the users home directory. This results in the gradle cache being put somewhere it really shouldn't be.
要解决此问题,我们只需要设置gradle的用户主目录即可. 此博客文章有很多做到这一点的方法.一种方法是创建GRADLE_USER_HOME环境变量,该变量具有适用于计算机上所有gradle构建的优点.
To fix the problem, then, we just need to set gradle's user home directory. This blog post has a bunch of ways to do that. One way is to create a GRADLE_USER_HOME environment variable, which has the advantage of applying to all gradle builds on the machine.
这篇关于AAPT2错误-在mergeDebugResources中找不到appcompat-v7文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!