Fix AAPT2 ERROR in Android Studio with non-ASCII characters in Windows user name

橙三吉。 提交于 2020-01-05 08:39:36

问题


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

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.

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.



Edit: 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.

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.

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: 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?


回答1:


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.

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

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)

Open File -> Settings -> 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.


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.



来源:https://stackoverflow.com/questions/50572845/fix-aapt2-error-in-android-studio-with-non-ascii-characters-in-windows-user-name

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