使用Windows用户名中的非ASCII字符修复Android Studio中的AAPT2错误 [英] Fix AAPT2 ERROR in Android Studio with non-ASCII characters in Windows user name

查看:169
本文介绍了使用Windows用户名中的非ASCII字符修复Android Studio中的AAPT2错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了最新的Android Studio并开始使用它。我创建了一个新的Navigationbar项目,并将一个gridview放入其中。然后,当我尝试构建和运行它时,我得到了这个非常烦人的AAPT2错误,请参阅日志以获取详细信息。

I installed the latest Android Studio and started to play around it. I created a new navigationbar project and put a gridview into it. Then when I try to build and run it I get this really annoying AAPT2 error, see logs for details.

我发现了几个修复,可以说这句话

I've found several "fixes" for this saying to set

android.enableAapt2 = false

如果我正确理解,实际上并不能解决问题,只是将建筑物恢复为aapt,对吗?而且由于AAPT2从现在起将成为真正的基础构建器,所以我坚持下去。

If I have understood correctly, that does not actually fix the problem, but just reverts the building back to aapt, am I right? And because AAPT2 is going to be the actual base builder from now on, I'd like to stick with it.

那我该如何实际解决这个问题呢?
首先,错误指向的日志在哪里?
其次,构建实际出了什么问题?即使我只是初始化一个全新的Android Studio示例项目,我也会收到此错误。

So how do I actual fix this problem then? First what and where are the logs the error is pointing to? And second, what is actually going wrong with the build? I get this error even, if I just initialize a brand new Android Studio example project.

编辑:
在Android Studio终端中运行 gradlew clean assembleDebug 命令,然后获得该疯狂的长输出。我将其剪切在这里,因为它重复了相同的模式:

Run the gradlew clean assembleDebug command in Android Studio Terminal and then got this insanely long output. I clipped it here, because it's repeating this same pattern:

C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-xxhdpi-v4\abc_ic_star_black_48dp.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-mdpi-v4\abc_list_pressed_holo_light.9.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-xxxhdpi-v4\abc_ic_menu_selectall_mtrl_alpha.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-mdpi-v4\abc_ab_share_pack_mtrl_alpha.9.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-hdpi-v4\abc_scrubber_primary_mtrl_alpha.9.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-hdpi-v4\abc_textfield_activated_mtrl_alpha.9.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\design-27.1.1.aar\ccb9f9993808b605fecf0f43596e26e5\res\layout\design_navigation_menu.xml: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-hdpi-v4\abc_list_pressed_holo_light.9.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-xxhdpi-v4\abc_btn_switch_to_on_mtrl_00001.9.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-xxxhdpi-v4\abc_ic_star_black_36dp.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-hdpi-v4\abc_ab_share_pack_mtrl_alpha.9.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\support-compat-27.1.1.aar\caef404a17c5959b4adfcdd5b4226763\res\drawable-xhdpi-v4\notification_bg_normal_pressed.9.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\color-v23\abc_color_highlight_material.xml: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-xhdpi-v4\abc_list_pressed_holo_light.9.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-mdpi-v4\abc_switch_track_mtrl_alpha.9.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-xxhdpi-v4\abc_ic_star_half_black_48dp.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\support-compat-27.1.1.aar\caef404a17c5959b4adfcdd5b4226763\res\drawable-xhdpi-v4\notification_bg_low_pressed.9.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-hdpi-v4\abc_btn_check_to_on_mtrl_015.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-hdpi-v4\abc_btn_check_to_on_mtrl_000.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-hdpi-v4\abc_list_focused_holo.9.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-mdpi-v4\abc_ic_star_half_black_36dp.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\anim\abc_grow_fade_in_from_bottom.xml: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\ff82df9d8c1253200bf8902d44d783bd\res\drawable-hdpi-v4\abc_text_select_handle_right_mtrl_dark.png: error: file not found.
C:\Users\M?tz\.gradle\caches\transforms-1\files-1.1\design-27.1.1.aar\ccb9f9993808b605fecf0f43596e26e5\res\layout\design_layout_snackbar.xml: error: file not found.

这里的问题是,我认为我的Windows用户名中包含非ASCII字符。即使我已指出Android Studio使用的文件夹不同于C:\Users下的任何文件夹,gradle仍需要在其中执行某些操作,并且显然不喜欢用户名中的'ä'字母。

The problem here is, I assume, that I have non-ASCII characters in my username in Windows. Even though I have pointed Android Studio to use different folders than anything under the C:\Users\\, gradle still needs to do something there and clearly doesn't like the 'ä' letter in my username.

如果是这种情况,那么我需要以某种方式告诉gradle使用其他文件夹或在Windows中更改我的用户名。我尝试了后者,但只设法更改了可见名称,而不是更改了Windows和文件夹结构中实际使用的基础名称。

If this is the case, then I'd need somehow to tell gradle to use those other folders as well or change my username in Windows. I've tried the latter, but only managed to change the visible name, not the underlying one that's actually used in Windows and in the folder structure.

Edit2:
如果不重新安装整个系统,则无法重命名Windows用户文件夹,这对我来说不是一个选择。因此,有没有办法更改正在使用的文件夹gradle?

Renaming the windows user folder is not possible without reinstalling the whole system and that's not an option for me this time. So is there a way to change the folder gradle is using?

推荐答案

这种情况下的问题是我有非ASCII码Windows用户名中的字符,以及我的用户文件夹和gradle中的字符都设置为使用此用户文件夹下的文件夹。您可以在Windows中更改可见的用户名,但是如果不重新安装就无法从用户文件夹中更改用户名。

The problem in this case was that I have non-ASCII characters in my Windows user name and thus in my user folder and gradle was set to use a folder under this user folder. You can change your visible user name in Windows, but you can not change your user name from your user folder without reinstalling.

幸运的是,您可以更改gradle使用的文件夹,从Android Studio设置。

Luckily you can change the folder gradle is using from Android Studio settings.

首先在文件系统中没有文件的位置创建一个 .gradle 文件夹非ASCII字符。 (我选择使用 C:\android-sdk\.gradle

First make a .gradle folder somewhere in your file system where you don't have those non-ASCII characters. (I chose to use C:\android-sdk\.gradle)

打开文件->设置-> Gradle

,您可以在其中选择Gradle使用的服务目录路径。将此更改为您创建的文件夹,即可解决此问题。

and there you can choose the "Service directory path" that Gradle is using. Change this to the folder you created and this problem should be solved.

注意!
在构建react-native android应用时,我也遇到了同样的问题,所以如果您来到这里,因为RN也遇到同样的AAPT2错误,请尝试从RN项目的gradle文件中更改gradle文件夹。目前,我不知道该怎么做,这也是另一个问题。

NOTE! I've faced this same problem when building react-native android apps too, so if you came here, because you got this same AAPT2 error with RN as well, try to change the gradle folder from you RN project's gradle files. At the moment I don't know how to do that and that's another question and topic too.

这篇关于使用Windows用户名中的非ASCII字符修复Android Studio中的AAPT2错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆