AAPT2 error - appcompat-v7 files not found in mergeDebugResources

自古美人都是妖i 提交于 2019-12-23 02:19:38

问题


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.

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.

So why is the build failing?


回答1:


As per the first linked question, disabling AAPT2 seems like a bad idea, as AAPT might be removed at some point in the future.

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.

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.

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.

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.



来源:https://stackoverflow.com/questions/50489991/aapt2-error-appcompat-v7-files-not-found-in-mergedebugresources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!