Bug 28721 - aapt error item with same key
Summary: aapt error item with same key
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 5.1
Hardware: PC Windows
: Normal normal
Target Milestone: 5.1.5 (C5SR3)
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2015-04-03 06:20 UTC by Andy
Modified: 2015-07-20 18:16 UTC (History)
4 users (show)

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


Attachments
repro project (30.88 KB, application/zip)
2015-07-20 18:16 UTC, Peter Collins
Details


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:
Status:
VERIFIED FIXED

Description Andy 2015-04-03 06:20:54 UTC
I've installed Xamarin.Android 5.1 and when trying to build from Visual Studio 2015 I get:

2>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1009,2): error MSB4018: The "Aapt" task failed unexpectedly.
2>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1009,2): error MSB4018: System.ArgumentException: An item with the same key has already been added.
2>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1009,2): error MSB4018:    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
2>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1009,2): error MSB4018:    at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
2>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1009,2): error MSB4018:    at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
2>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1009,2): error MSB4018:    at Xamarin.Android.Tasks.Aapt.Execute()
2>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1009,2): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
2>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1009,2): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__1.MoveNext()
2>Done executing task "Aapt" -- FAILED. (TaskId:186)

Note this didn't happen with Xamarin.Android 4.20
Comment 1 Jonathan Pryor 2015-04-03 09:53:49 UTC
@Andy: It's possible that there are stale build artifacts causing duplicates. Please try deleting your `obj` and `bin` directories, then rebuilding.

@Dean: We should at minimum provide better error reporting here, or fix things so that we're not getting these duplicate files in the first place...
Comment 2 dean.ellis 2015-04-03 10:24:22 UTC
I've seen this on the MonoGame projects recently. I'll get into it asap.
Comment 3 Andy 2015-04-06 17:42:28 UTC
Tried deleting obj and bin folders but no difference.  Would definitely help to have a more detailed error to see what file is duplicated
Comment 4 dean.ellis 2015-04-09 08:33:41 UTC
one other thing to check . Make sure that all of your projects have their own IntermediateOutputPath setting  (i.e. don't build intermediate files to the same place). This will cause problems with Native Libraries as it will just pick up what is there and has no way of knowing if the files actually belong to the project.

I'm working on adding duplicate checks to the BuildApk task which will issues warnings for duplicate files which are the same, and errors for files that are Not.
Comment 5 Andy 2015-04-09 16:41:38 UTC
My solutions is very simple
1x PCL Project
1x Android Project

Both build to their own output folders.

Not sure how I am getting this error when it seems such a simple solution.  Will wait and see what the more detailed errors/warnings bring in a future update

Thanks
Comment 6 dean.ellis 2015-04-13 06:27:14 UTC
The only way I have managed to replicate this is by using Linked files. For example I have a test.axml file in Resources\layout\.

Next I put in "linked" files in Resources\layout-xhdpi one called test.axml and one called Test.axml both of these files link to the layout in Resources\layout\test.axml

Now because we must convert to lower case for android packaging we end up getting this error because Test.axml and test.axml end up with the same name. 

I'm looking at putting in a warning for this which will highlight the conflict. In the mean time check your csproj carefully for what could be case collisions or duplicates.
Comment 7 Andy 2015-04-13 07:42:31 UTC
Could this error perhaps be coming from third party components?  I don't have any links in my project and no duplicates.
Comment 8 dean.ellis 2015-04-13 08:06:45 UTC
Possibly. 

any chance you could post up the full diagnostic build output? That will help me track down exactly what is causing the problem in the project. You'll need to enable Diagnostic msbuild output in VS/XS as that will give us all the extra info we need. 

If you'd rather not attach it to this bug, feel free to email it to me directly.
Comment 9 Andy 2015-04-14 11:06:22 UTC
Ok, I've tracked down the duplicate layout file that was actually in my solution.  It would still be useful to have the details of the duplicate if it occurs in the future though.

Thanks,
Comment 10 Jonathan Pryor 2015-06-03 11:35:07 UTC
Fixed in monodroid/0c65bbbb.
Comment 11 Peter Collins 2015-07-20 18:16:21 UTC
I was able to force this error with the newly attached project. Cleaning and rebuilding is now succeeding on the current Alpha.
Comment 12 Peter Collins 2015-07-20 18:16:55 UTC
Created attachment 12122 [details]
repro project