locked
'Error MSB4018: The "Aapt" task failed unexpectedly' on new Android Application. No code added. RRS feed

  • Question

  • User12053 posted

    Just installed Xamarin. Open Xamarin Studio Create new Android Application. Hit run and get the following error:

    C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2,2): Error MSB4018: The "Aapt" task failed unexpectedly. System.InvalidOperationException: Sequence contains no elements at System.Linq.Enumerable.First[TSource](IEnumerable`1 source) at Xamarin.Android.Tasks.BuildToolsUtils.GetBuildToolsPath(String androidSdkDirectory) at Xamarin.Android.Tasks.Aapt.GenerateFullPathToTool() at Microsoft.Build.Utilities.ToolTask.ComputePathToTool() at Microsoft.Build.Utilities.ToolTask.Execute() at Xamarin.Android.Tasks.Aapt.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext() (MSB4018) (test)

    Have looked around on this site and tried a few things but no joy. Any Ideas?

    Saturday, May 18, 2013 12:34 AM

All replies

  • User12084 posted

    I have just installed the trial today and have also got a very similar error:

    Error 1 The "Aapt" task failed unexpectedly. System.InvalidOperationException: Sequence contains no elements at System.Linq.Enumerable.First[TSource](IEnumerable`1 source) at Xamarin.Android.Tasks.BuildToolsUtils.GetBuildToolsPath(String androidSdkDirectory) at Xamarin.Android.Tasks.Aapt.GenerateFullPathToTool() at Microsoft.Build.Utilities.ToolTask.ComputePathToTool() at Microsoft.Build.Utilities.ToolTask.Execute() at Xamarin.Android.Tasks.Aapt.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext() AndroidApplication1

    Saturday, May 18, 2013 7:48 AM
  • User12084 posted

    Update:

    Fixed my issue by opening the Android SDK Manager and installing the packages that were available.

    Not sure if this is the correct response, but it was a iffy SDK install that was causing my issue.

    The Android path was C:\Users\USERNAME\AppData\Local\Android

    Which I'm not 100% would be the default location, perhaps the installer is putting it in there?

    Saturday, May 18, 2013 9:00 AM
  • User12090 posted

    I also have this error, it worries me that there are not offical answers to this kind og bug.

    Saturday, May 18, 2013 9:21 AM
  • User12091 posted

    I am also facing the same problem..... Pls reply me as soon as possible... Thanks in advance

    Saturday, May 18, 2013 9:31 AM
  • User10447 posted

    Even i got the same Error but fixed it by opening the Android SDK Manager and updating the Android SDK platform-tools under tools sections.

    Saturday, May 18, 2013 10:37 AM
  • User12090 posted

    How does one update the Android SDK platform-tools under tools section? I se no possibility to update?

    Saturday, May 18, 2013 10:53 AM
  • User12090 posted

    I am glad I am only trying out this software and have not bought it yet. Never seems to work.

    Saturday, May 18, 2013 10:54 AM
  • User12090 posted

    I solved the problem by going into the directory: C:\Users\Christian\AppData\Local\Android\android-sdk and doubleclicked the sdk manager.exe. this UI showed that there 12 packages for installation i installed these.

    Saturday, May 18, 2013 11:26 AM
  • User12188 posted
    1. Launch Android SDK Manager
      • click on Start button -> All programs -> Android SDK Tools -> SDK Manager
      • OR run "C:\Users\YOUR_USERNAME\AppData\Local\Android\android-sdk\SDK Manager.exe"
    2. Install package "Android SDK Build-tools". It is not necessary to install other packages.
    Sunday, May 19, 2013 9:36 PM
  • User10708 posted

    AlvinStraight, thank you

    Tuesday, May 21, 2013 8:03 AM
  • User12366 posted

    I have just installed the trial today and have also got a very similar error:

    C:\Program Files\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2,2): Error MSB4018: The "Aapt" task failed unexpectedly.

    System.InvalidOperationException: Sequence contains no elements

    at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)

    at Xamarin.Android.Tasks.BuildToolsUtils.GetBuildToolsPath(String androidSdkDirectory)

    at Xamarin.Android.Tasks.Aapt.GenerateFullPathToTool()

    at Microsoft.Build.Utilities.ToolTask.ComputePathToTool()

    at Microsoft.Build.Utilities.ToolTask.Execute()

    at Xamarin.Android.Tasks.Aapt.Execute()

    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()

    at Microsoft.Build.BackEnd.TaskBuilder.d_20.MoveNext() (MSB4018) (HelloWorld)

    Tuesday, May 21, 2013 11:52 AM
  • User48 posted

    I have just installed the trial today and have also got a very similar error:

    You have a $ANDROID_SDK_PATH/build-tools directory, but there is nothing inside of it. Please install the Android SDK Build-tools package.

    Tuesday, May 21, 2013 2:17 PM
  • User12563 posted

    I reinstalled the build tools (at least I think I did) but still not working. I also downloaded the trial version (4.0.8)

    Thursday, May 23, 2013 6:37 AM
  • User48 posted

    Can you provide diagnostic build output?

    Thursday, May 23, 2013 3:03 PM
  • User12563 posted

    Here it is:

    C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2,2): Error MSB4018: The "Aapt" task failed unexpectedly.
    System.InvalidOperationException: Sequence contains no elements
       at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
       at Xamarin.Android.Tasks.BuildToolsUtils.GetBuildToolsPath(String androidSdkDirectory)
       at Xamarin.Android.Tasks.Aapt.GenerateFullPathToTool()
       at Microsoft.Build.Utilities.ToolTask.ComputePathToTool()
       at Microsoft.Build.Utilities.ToolTask.Execute()
       at Xamarin.Android.Tasks.Aapt.Execute()
       at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
       at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext() (MSB4018) (TaskyAndroid)
    
    Thursday, May 23, 2013 5:14 PM
  • User2812 posted

    I was receiving the compiler exception that russd2357 posted.

    I heeded the advice above from: Chris Nelis, Christian Andersen, and Alvin Straight and updated the 'Android SDK build-tools'. There advice resolved my issue immediately.

    To resolve the error, your dev environment needs to be running Android SKD Build-tools, Rev 17. Updating to Rev 17 is easy to overlook because it appears to occur over a two-part install, via the SDK Manager. The first update via the SDK Manager will update several packages but only after that first update completes does the Android SDK build-tools Rev 17 become available for update through the SDK Manager.

    Got questions, tweet me: @benhorgen

    Thursday, May 23, 2013 7:16 PM
  • User4715 posted

    I have build-toold version 17 (looks like latest) installed. When I build the project I get in XS: C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2,2): Error XA5205: Cannot find aapt. Please install the Android SDK Build-tools package with the C:\Users\yuris\AppData\Local\Android\android-sdk/android program. (XA5205) (AdnroidApp3)

    Thursday, May 23, 2013 8:44 PM
  • User12563 posted

    Yes, I have build tools v. 17 as well. I'm sure it's probably something really basic that I'm missing.

    Thursday, May 23, 2013 10:56 PM
  • User48 posted

    @YuriShteinman: You're using the latest alpha release on Windows, which had no QA, and (unfortunately) had a regression in that area. It will be fixed in 4.7.6.

    Friday, May 24, 2013 2:59 AM
  • User48 posted

    @russd2357: Unfortunately, I don't know what's wrong on your machine. Does $(AndroidSdkDirectory)\build-tools\17.0.0\aapt.exe (e.g. C:\Users\USER_NAME\AppData\Local\Android\android-sdk\build-tools\17.0.0\aapt.exe) exist?

    Do you have more than one Android SDK installed? Is Xamarin Studio/Visual Studio referring to the right one?

    Friday, May 24, 2013 3:03 AM
  • User12563 posted

    That was exactly what the problem was! I had installed another Android sdk before i got Xamarin Studio, and the SDK Manager shortcut i was using pointed to the wrong one. When i launched the correct one and installed the build tools from there, i was good to go. Thanks! Like i guessed, it was something simple

    Friday, May 24, 2013 3:12 AM
  • User4715 posted

    @jonp The update to alpha was suggested by your support trying to fix another bug. Your guys should be more careful with their advices. Now I have to spend half day rolling everything back to 4.6 Do you have an estimation when 4.7.6 is going to be available?

    Friday, May 24, 2013 4:09 PM
  • User12735 posted

    I had the similar issue exactly with the same error message but for the first time the application was built successfully when there were no emulators, when I created a new emulator to test the application then I saw this error tying to build.

    As suggested I have installed the 12 packages (it will take some time but you have to wait) error disappeared.

    One issue is when you try to debug applications, start your emulators first, if it is first time there studio will do another silent installation while compiling, so be patient.

    After those glitches, I am a happy developer.

    Friday, May 24, 2013 4:43 PM
  • User7236 posted

    I just started experiencing this error too and it is very random! please help

    Friday, May 24, 2013 7:33 PM
  • User7236 posted

    updating the android tools fixed this for me

    Friday, May 24, 2013 7:56 PM
  • User12866 posted

    Got the same error as you guys!!!

    C:\Program Files\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(3,3): Error MSB4018: The "Aapt" task failed unexpectedly.

    System.InvalidOperationException: Sequence contains no elements

    at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)

    at Xamarin.Android.Tasks.BuildToolsUtils.GetBuildToolsPath(String androidSdkDirectory)

    at Xamarin.Android.Tasks.Aapt.GenerateFullPathToTool()

    at Microsoft.Build.Utilities.ToolTask.ComputePathToTool()

    at Microsoft.Build.Utilities.ToolTask.Execute()

    at Xamarin.Android.Tasks.Aapt.Execute()

    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()

    at Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext() (MSB4018) (SNMPGet)

    I followed jonp advice and updated my Android SDK Platform tools and it worked fine!

    I'm realizing that it only worked because it is pointing to API 17 and I didn't had my SDK updated.

    Just one thing. Does this mean that we have to work with API 17? Thanks!

    Sunday, May 26, 2013 6:44 PM
  • User12767 posted

    to me too

    Sunday, May 26, 2013 9:47 PM
  • User5430 posted

    Your code in [Xamarin.Android.Build.Tasks]Xamarin.Android.Tasks.ResolveSdks.Execute() is wrong. You look for a file named "aapt" while on Windows the file is called "aapt.exe".

    P.S. What does "Please install the Android SDK Build-tools package with the SdkPath/android program." even mean?

    Monday, May 27, 2013 7:33 AM
  • User9946 posted

    As Ark-kun mentioned the code has a bug. And yes the error is kind of funny .. ;)

    if (Directory.Exists(str) && File.Exists(Path.Combine(str, "aapt")))

    But the file is called aapt.exe

    Create a copy of your aapt.exe named aapt.

    The file should be located in:

    android-sdk\build-tools\17.0.0

    This worked for me!

    Edit: I also needed to copy my java.exe to android-sdk\build-tools\17.0.0

    Monday, May 27, 2013 12:30 PM
  • User13293 posted

    Dear Friends

    I also got the same problem which is as below

    C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2,2): Error MSB4018: The "Aapt" task failed unexpectedly.

    System.InvalidOperationException: Sequence contains no elements

    at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)

    at Xamarin.Android.Tasks.BuildToolsUtils.GetBuildToolsPath(String androidSdkDirectory)

    at Xamarin.Android.Tasks.Aapt.GenerateFullPathToTool()

    at Microsoft.Build.Utilities.ToolTask.ComputePathToTool()

    at Microsoft.Build.Utilities.ToolTask.Execute()

    at Xamarin.Android.Tasks.Aapt.Execute()

    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()

    at Microsoft.Build.BackEnd.TaskBuilder.d_20.MoveNext() (MSB4018) (HelloWorld)

    Please help if anyone of you have solve the issue

    Thursday, May 30, 2013 10:36 AM
  • User13293 posted

    I just opened Android SDK manager and found that there are 13 install packages are pending, installing those packages, let see what will happen after that...will update after this

    Thursday, May 30, 2013 10:42 AM
  • User13523 posted

    I updated my sdk manager and worked. i suggest do that.

    Saturday, June 1, 2013 12:57 PM
  • User1568 posted

    http://forums.xamarin.com/discussion/comment/15360/#Comment_15360

    Wednesday, June 12, 2013 8:58 PM
  • User8541 posted

    This Solved my Issue:

    AS POSTED BY: AlvinStraight

    1.Launch Android SDK Manager •click on Start button -> All programs -> Android SDK Tools -> SDK Manager •OR run "C:\Users\YOUR_USERNAME\AppData\Local\Android\android-sdk\SDK Manager.exe"

    2.Install package "Android SDK Build-tools". It is not necessary to install other packages.

    Friday, June 21, 2013 4:49 AM
  • User15456 posted

    I just installed Xamerine on top of VS 2010 and I am facing the same issue when trying to build the app. Error 1 The "Aapt" task failed unexpectedly. System.InvalidOperationException: Sequence contains no elements at System.Linq.Enumerable.First[TSource](IEnumerable`1 source) at Xamarin.Android.Tasks.BuildToolsUtils.GetBuildToolsPath(String androidSdkDirectory) at Xamarin.Android.Tasks.Aapt.GenerateFullPathToTool() at Microsoft.Build.Utilities.ToolTask.ComputePathToTool() at Microsoft.Build.Utilities.ToolTask.Execute() at Xamarin.Android.Tasks.Aapt.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext() AndroidTestApp

    Even I don't find the path C:\Users\USER_NAME\AppData\Local\Android\android-sdk as mentioned in this thread to do any update. Please suggest.

    Friday, June 21, 2013 9:53 AM
  • User8505 posted

    1.Launch Android SDK Manager •click on Start button -> All programs -> Android SDK Tools -> SDK Manager

    Friday, June 21, 2013 11:27 AM
  • User6225 posted

    Hey Guys, I experienced the same issue. I was working on our app, everything was working fine. I started the android monitor because I wanted to check some memory use and then hell broke loose and I got the appt error. I solved it by updating the sdk tools, platform tools and build tools as suggested.

    Tuesday, June 25, 2013 8:17 AM
  • User17146 posted

    You need to set anroid SDk path in options. I did and compiled it worked

    Monday, July 8, 2013 9:50 AM
  • User17796 posted

    I had the same issue, I had to add a proxy setting in SDK manager so It would download. After that it ran fine.

    Monday, July 15, 2013 8:32 PM
  • User293999 posted

    Had the same issue solved it my reverting my Manifest. The problem a space between the application level xml and android keyword

    Monday, August 14, 2017 10:05 AM
  • User339450 posted

    Download Bitdefender Total Security 2018 it had a feature to Protect Files from getting changed thus blocking every attempt for the app to run normally on the emulator. I Disabled it and it worked perfectly CHECK YOUR ANTIVIRUS Software.

    Tuesday, September 12, 2017 6:33 AM
  • User351183 posted

    Similar issues with Comodo AV. Disabling it solved the problem,

    Saturday, September 30, 2017 6:36 AM
  • User294116 posted

    Check you version number in android manifest, don use dots. 1.0.1 use only numbers -> 101

    Thursday, November 2, 2017 5:20 PM
  • User230417 posted

    In my case was an error in manifest!

    Thursday, December 7, 2017 4:33 PM
  • User324174 posted

    Resolved for me: In the project properties window. I had made version number and version name as 2.2 . This created a problem. Looks like it expects a whole number.

    Thursday, March 8, 2018 8:20 PM
  • User365854 posted

    In Android Manifest, I had entered "0.1" as version number. Turns out it only accepts integer values so changing to "1" solved it.

    Monday, March 26, 2018 8:44 AM