Bug 43081 - VS hangs often due to aapt.exe
Summary: VS hangs often due to aapt.exe
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 7.0 (C8)
Hardware: PC Windows
: Normal normal
Target Milestone: 7.2 (C10)
Assignee: dean.ellis
Depends on:
Reported: 2016-08-05 10:00 UTC by kontakt
Modified: 2017-02-13 22:09 UTC (History)
6 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description kontakt 2016-08-05 10:00:36 UTC
I am experiencing troubles with aapt.exe .. very often it suddenly takes about 35% of CPU and causes Visual Studio to hang. E.g. when I try to install Nuget to Android project, it hangs for about 10 minutes. When I build and deploy Android project, it hangs every time for about 30 seconds longer than it should. Even if I build iOS project and Android project is not unloaded, it also hangs about 30 seconds (when I unload the Android project, it does not happen). And also after I open some Android xml in Android Designer, then every saving of any xml file hangs for about 30 seconds - when I reboot PC, this xml-problem does not happen but when I open xml in Android Studio, it happens again until I reboot.

Every time this hang occurs, aapt.exe is on the top of CPU usage.

I managed to workaround this issue by adding <AndroidResgenExtraArgs>--no-crunch </AndroidResgenExtraArgs> to the Android .csproj file. When I do this, aapt.exe is not taking CPU and VS is not hanging. But some UI on android looks ugly (like compatswitch, tablayout etc).

My co-worker is experiencing the same issue, so it's not just me.

Xamarin version:
Xamarin Android version:
Xamarin iOS version:
Comment 1 Jonathan Pryor 2016-09-13 15:46:49 UTC
Which version of the Android SDK Build-tools package do you have installed? Is it 24.*?

Possible workaround: rename your .png files to .PNG, but *not* .9.png files.

via: https://groups.google.com/forum/#!topic/android-developers/DT-i8QK27Iw
Comment 2 dean.ellis 2016-09-13 15:49:08 UTC
rather than manually adding --no-crunch we have a different build property


which you can set. In this case aapt will be run to produce a cache of crunched .png files and only the changes will be crunched after that. So the first build might be slow but following ones should be quick.

The reason the ui looks ugly is because files like 9 patch files (foo.9.png) need to be pre-processed to remove some of the information they contain and other files need to be optimised by the android build system.
Comment 3 kontakt 2016-09-13 16:43:46 UTC
Yes, I have 24.0.1 SDK Build-tools.

Thanks for the PNG workaround suggestion, but it seems complicated as we have many .png files in many folders, I think it's not worth the effort.

AndroidExplicitCrunch property works great - the second build is fast and it does not produce ugly UI. Is it safe to set this property to true even for production, release builds?

Still, without using this property, why is aapt.exe called even if I build and deploy iOS only? That is weird. I could add this AndroidExplicitCrunch property even in iOS project configuration, but it does not look like good practice.
Comment 4 dean.ellis 2016-11-14 12:55:47 UTC
AndroidExplicitCrunch should be safe for production/release builds.

I'm not sure why the aapt is being called when you build the iOS project. I would check the solution configuration and make sure that the android project is not set to build when you are targeting iOS. 

Its possible that the intellisense build in VS is tripping up the IDE. We have made some changed in the latest stable releases to speed up the intellisense builds and to ensure they do not do work they should not be doing. 

If you are still getting issues with aapt locking up the IDE can you provide some diagnostic build logs. This will enable use to see what targets are being run.