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

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:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-xxhdpi-v4abc_ic_star_black_48dp.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-mdpi-v4abc_list_pressed_holo_light.9.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-xxxhdpi-v4abc_ic_menu_selectall_mtrl_alpha.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-mdpi-v4abc_ab_share_pack_mtrl_alpha.9.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-hdpi-v4abc_scrubber_primary_mtrl_alpha.9.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-hdpi-v4abc_textfield_activated_mtrl_alpha.9.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1design-27.1.1.aarccb9f9993808b605fecf0f43596e26e5reslayoutdesign_navigation_menu.xml: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-hdpi-v4abc_list_pressed_holo_light.9.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-xxhdpi-v4abc_btn_switch_to_on_mtrl_00001.9.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-xxxhdpi-v4abc_ic_star_black_36dp.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-hdpi-v4abc_ab_share_pack_mtrl_alpha.9.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1support-compat-27.1.1.aarcaef404a17c5959b4adfcdd5b4226763resdrawable-xhdpi-v4notification_bg_normal_pressed.9.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdrescolor-v23abc_color_highlight_material.xml: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-xhdpi-v4abc_list_pressed_holo_light.9.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-mdpi-v4abc_switch_track_mtrl_alpha.9.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-xxhdpi-v4abc_ic_star_half_black_48dp.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1support-compat-27.1.1.aarcaef404a17c5959b4adfcdd5b4226763resdrawable-xhdpi-v4notification_bg_low_pressed.9.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-hdpi-v4abc_btn_check_to_on_mtrl_015.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-hdpi-v4abc_btn_check_to_on_mtrl_000.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-hdpi-v4abc_list_focused_holo.9.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-mdpi-v4abc_ic_star_half_black_36dp.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresanimabc_grow_fade_in_from_bottom.xml: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1appcompat-v7-27.1.1.aarff82df9d8c1253200bf8902d44d783bdresdrawable-hdpi-v4abc_text_select_handle_right_mtrl_dark.png: error: file not found.
C:UsersM?tz.gradlecachestransforms-1files-1.1design-27.1.1.aarccb9f9993808b605fecf0f43596e26e5reslayoutdesign_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?

Answer

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.