Bug 21361 - Attribute "<attribute name>" has already been defined, when having attributes defined in a Android Class Library and using Android Binding component
Summary: Attribute "<attribute name>" has already been defined, when having attributes...
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Tools and Addins ()
Version: 4.14.0
Hardware: PC Windows
: Normal normal
Target Milestone: 5.1
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-07-16 05:17 UTC by Tomasz Cielecki
Modified: 2015-05-05 13:43 UTC (History)
25 users (show)

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


Attachments
Project which produces the error (1.30 MB, application/x-zip-compressed)
2014-07-17 05:05 UTC, Tomasz Cielecki
Details
Test Case (98.44 KB, application/zip)
2014-08-06 15:28 UTC, John Miller [MSFT]
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 Tomasz Cielecki 2014-07-16 05:17:19 UTC
Xamarin 3.3.30.0
Visual Studio 2013 Update 2 / Xamarin.Studio 5.2 (366)

As the title says, when having declared styleables in an Android Class Library project, having a reference to this project in an Android Application project, while using Android Binding library components, such as Android Support v4, breaks the build telling that the attributes defined in the Android Class Library have already been defined.

So somewhere in the build process something goes wrong and makes it impossible to build the Application project.
Comment 1 Tomasz Cielecki 2014-07-16 05:30:56 UTC
This is also a problem with Xamarin 3.2.5.0
Comment 2 Jonathan Pryor 2014-07-16 11:25:46 UTC
Please provide a test case.
Comment 3 Tomasz Cielecki 2014-07-17 05:05:59 UTC
Created attachment 7406 [details]
Project which produces the error
Comment 4 Tomasz Cielecki 2014-07-17 05:23:34 UTC
If I create a new solution with the following structure I cannot reproduce the problem:

Android Class Library
   Resources
      values
         attrs.xml
Android Application Project
   Resources
      values
         otherattrs.xml

neither if I create more Android Class libraries in the solution. But as soon as I reference the Cheesebaron.MvxBindings.GroupListView.Droid dll in the libs folder to the Application project it produces the error. So something might be wrong there. That project can be found here: https://github.com/Cheesebaron/Cheesebaron.MvxBindings
Comment 5 Jonathan Pryor 2014-08-02 09:15:50 UTC
Unfortunately, I am not able to build Attachment #7406 [details].

> Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Cirrious.MvvmCross.Localization, Version=1.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
> File name: 'Cirrious.MvvmCross.Localization.dll'

I also don't see Cirrious.MvvmCross.Localization.dll in the project.
Comment 6 softlion 2014-08-06 10:18:56 UTC
+1, same bug
Comment 7 softlion 2014-08-06 10:19:36 UTC
A fix: build the project with Xamarin Studio, then go back to visual studio: magically it works !
Comment 8 Jonathan Pryor 2014-08-06 10:35:26 UTC
@kzu: Seems that this may be a VS-specific issue?

(A working repro would still be nice...)
Comment 9 softlion 2014-08-06 10:38:58 UTC
I'm unable to repro. If i create a new project and reference the offending android library it works.
Comment 10 softlion 2014-08-06 10:39:26 UTC
But i also have support v4 installed, but not the latest version
Comment 11 softlion 2014-08-06 10:39:50 UTC
maybe it is related, i haven't checked.
Comment 12 Greg Ferreri 2014-08-06 11:19:45 UTC
I'm also seeing this error. I can compile in Visual Studio 2013, but cannot compile in Xamarin Studio 5.2 under Mac.
Comment 13 softlion 2014-08-06 14:04:17 UTC
Ok, so this is a critical bug.

It appeared as soon as we recompile the Android lib project containing resources with the latest stable version (visual studio or xamarin studio), and we add this lib as ref to an android project in visual studio.
Comment 14 softlion 2014-08-06 14:04:38 UTC
Only workaround is to use Xamarin Studio, not Visual studio at all.
Comment 15 softlion 2014-08-06 14:20:24 UTC
ok i have a repro project !
Comment 17 softlion 2014-08-06 14:43:57 UTC
private comment added.
Comment 18 softlion 2014-08-06 14:49:11 UTC
And the diff between the repro project and the project witch works is in the .csproj file:

Compiling:

    <Reference Include="Xam.Droid">
<HintPath>..\packages\Some.1.0.12\lib\MonoAndroid\Xam.Droid.dll</HintPath>
    </Reference>


Not compiling:

    <Reference Include="Xam.Droid, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Some.1.0.12\lib\MonoAndroid\Xam.Droid.dll</HintPath>
    </Reference>



It seems removing then adding the same package through nugets adds incorrect Version and processorArchitecture information ... And it seems Xamarin really does not like that !

I removed the version from the failing project and ... it compiles !!

Howdy !
Comment 19 John Miller [MSFT] 2014-08-06 15:27:50 UTC
** Additional Information**

I attached a test case for this.

I noticed this issue when only updating from XA 4.12.6 -> 4.14. The project will build and run fine in 4.12.6, but it fails to compile on 4.14 with this error:

** Actual Results **

>/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Tool exited with code: 1. Output: >/Users/John/Projects/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res/values/attrs.xml:1: error: Attribute "ahText" has already been defined
>/Users/John/Projects/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res/values/attrs.xml:1: error: Attribute "ahTextColor" has already been defined
>/Users/John/Projects/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res/values/attrs.xml:1: error: Attribute "ahTextSize" has already been defined
>/Users/John/Projects/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res/values/attrs.xml:1: error: Attribute "ahBarColor" has already been defined
>/Users/John/Projects/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res/values/attrs.xml:1: error: Attribute "ahRimColor" has already been defined
>/Users/John/Projects/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res/values/attrs.xml:1: error: Attribute "ahRimWidth" has already been defined
>/Users/John/Projects/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res/values/attrs.xml:1: error: Attribute "ahSpinSpeed" has already been defined
>/Users/John/Projects/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res/values/attrs.xml:1: error: Attribute "ahDelayMillis" has already been defined
>/Users/John/Projects/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res/values/attrs.xml:1: error: Attribute "ahCircleColor" has already been defined
>/Users/John/Projects/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res/values/attrs.xml:1: error: Attribute "ahRadius" has already been defined
>/Users/John/Projects/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res/values/attrs.xml:1: error: Attribute "ahBarWidth" has already been defined
>/Users/John/Projects/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res/values/attrs.xml:1: error: Attribute "ahBarLength" has already been defined
 >(XFormsTest.Android)

** Note ** 

The test case includes some DLLs that are referenced to reproduce the issue. There are two components required: Xamarin.Mobile and JSON.NET, please restore those.
Comment 20 John Miller [MSFT] 2014-08-06 15:28:09 UTC
Created attachment 7607 [details]
Test Case
Comment 21 John Miller [MSFT] 2014-08-06 15:28:31 UTC
Added test case now.
Comment 22 Bjarke Pedersen 2014-08-11 06:54:49 UTC
I am having the same issue, but I am having it in both xs and vs 2013 :(
Comment 23 softlion 2014-08-11 07:55:28 UTC
In your csproj file, remove ", Version=0.0.0.0, Culture=neutral,
processorArchitecture=MSIL" from all references like this:

    <Reference Include="Xam.Droid, Version=0.0.0.0, Culture=neutral,
processorArchitecture=MSIL">

to

    <Reference Include="Xam.Droid">
Comment 24 Bjarke Pedersen 2014-08-11 08:04:48 UTC
It still fails after removing those lines
Comment 25 Rui Marinho 2014-08-11 11:55:01 UTC
Just wanted to report we are having the same problem on the Xamarin Forms Labs library the comunity is working on:

you can get more details in this issue discussion, as well as workaround.
https://github.com/XForms/Xamarin-Forms-Labs/issues/172#issuecomment-51794962

it's important to say that this bug only arrise in the last update of Xamarin Tools on Windows.
Comment 26 softlion 2014-08-11 16:34:06 UTC
The workaround does not work anymore :( Even on Xamarin Studio.
Comment 27 Kevin Ford 2014-08-12 07:15:03 UTC
Softlion,
The workaround was working as of last night.  

Let me whip up a quick test project.  I'm pretty sure I know how to recreate this on demand.
Comment 28 softlion 2014-08-12 07:28:00 UTC
It's magic, sometime updating a nuget fixes the bug, sometime it triggers it.
Comment 29 Bjarke Pedersen 2014-08-12 07:31:58 UTC
Did you update an nuget package for the workaround to work?
Comment 30 softlion 2014-08-12 07:50:17 UTC
yes
Comment 31 Bjarke Pedersen 2014-08-12 07:59:39 UTC
any specfic?
Comment 32 softlion 2014-08-12 09:00:57 UTC
No its my own package. Sometime after updating it it starts to bug (and never ends), sometime after updating it it compiles.

This seem a temp file issue. I cleaned temp folders without success.
Comment 33 softlion 2014-08-12 11:26:56 UTC
Now it compiles ok in debug mode but not in release mode !
Comment 34 Bjarke Pedersen 2014-08-13 02:30:27 UTC
just updated to 5.2.1 still no luck
Comment 35 softlion 2014-08-13 04:26:14 UTC
I get back to previous Xamarin version, now it is ok.
Comment 36 John Miller [MSFT] 2014-08-13 12:32:22 UTC
As a workaround, I have noticed that Xamarin.Android 4.12.6 does not have this issue. 

I also noticed that I got this error because I was referencing a library (AndHUD.dll) that _another_ library was also referencing. I removed AndHUD.dll and the issue went away.
Comment 37 softlion 2014-08-13 13:29:50 UTC
Yes and the bug is also triggered by android support v4. But who wants to remove it ?
Comment 38 Fixicar Team 2014-08-26 15:43:36 UTC
Hey guys,

I am having the same issue while referencing Xamarin.Forms.Labs.

Are there any updates on this issue or maybe someone has a workaround which is actually works?

I am on Xamarin Studio 5.2.1 at the moment.
Comment 39 Bill Dwyer 2014-08-27 16:07:15 UTC
I am also experiencing this issue by using the new Xamarin.Android.Support.v4 library. I have Xamarin 3.3.47.0 installed on Windows.
Comment 40 Bill Dwyer 2014-08-27 16:28:22 UTC
Looks like I've found the source of my "Attribute '<attribute name>' has already been defined" issue.

In my build log, I notice the following:

*********************

AdditionalAndroidResourcePaths: 

C:\Users\bdwyer\AppData\Local\Android\android-sdk\build-tools\19.1.0\aapt.exe package -f -m -M C:\Users\bdwyer\AppData\Local\Temp\wybcde24.nln\AndroidManifest.xml -J C:\Users\bdwyer\AppData\Local\Temp\wybcde24.nln --custom-package com.shiftwise.connect -F C:\Users\bdwyer\AppData\Local\Temp\wybcde24.nln\resources.apk.bk -S obj\Debug\res  -S "C:\dev\**one**\library_project_imports\res" -S "C:\dev\**two**\__library_projects__\SQLite\library_project_imports\res" -S "C:\dev\**three**\__library_projects__\PullToRefresharp\library_project_imports\res" -I C:\Users\bdwyer\AppData\Local\Android\android-sdk\platforms\android-14\android.jar --auto-add-overlay --max-res-version 14

*********************

I am using the PullToRefresharp component, but it is looping through the resource folder twice, and causing the conflict.

I'm not sure how to resolve this.

Thoughts?
Comment 41 softlion 2014-08-27 18:12:09 UTC
This seems fixed in the alpha channel, which has other issues.
Comment 42 John Miller [MSFT] 2014-08-29 12:50:16 UTC
It looks like I am not getting this with 4.17, but it has other issues preventing the build from working: 
>.../NodeAlreadyInTreeException.java(3,3): Error:  cannot find symbol
>symbol  : constructor RuntimeException(java.lang.String,java.lang.Throwable,boolean,boolean)
>location: class java.lang.RuntimeException super (p0, p1, p2, p3);
Comment 43 softlion 2014-08-30 04:15:02 UTC
I fixed all issues that were raised when compiling with alpha channel. It works !
Comment 44 Kevin Ford 2014-09-02 11:08:33 UTC
I wasn't able to get it to work with the alpha channel version but perhaps I did something wrong.  For right now on Xamarin.Labs.Forms we ended up removing the attributes completely from the Android renderer project.  The calendar no longer works correctly but now people can compile while referencing our package.  

Hopefully it will be fixed soon.
Comment 45 Jonathan Pryor 2014-09-09 12:14:10 UTC
@Kzu: This was originally assigned to you because of Comment #18, though Comment #19 shows it's not actually a VS-related problem, it's a general build system problem.

@John: Thank you for Attachment #7607 [details].

The actual problem is a build system bug; the problem is in the `aapt` invocation (formatted for readability):

> Tool /opt/android/sdk-tool/sdk/build-tools/20.0.0/aapt execution started with arguments:
> 	package -f -m -M /var/folders/1y/wwmg3hv5685ft661f5q2w2100000gn/T/s2pw3pcp.yps/AndroidManifest.xml
> 	-J /var/folders/1y/wwmg3hv5685ft661f5q2w2100000gn/T/s2pw3pcp.yps --custom-package xformstest.android
> 	-F /var/folders/1y/wwmg3hv5685ft661f5q2w2100000gn/T/s2pw3pcp.yps/resources.apk.bk
> 	-S obj/Debug/res/
> 	-S /Users/jon/Downloads/bxc-21361/XFormsTest/Android/obj/Debug/__library_projects__/Xamarin.Forms.Platform.Android/library_project_imports/res
> 	-S /Users/jon/Downloads/bxc-21361/XFormsTest/Android/obj/Debug/__library_projects__/Acr.XamForms.Mobile.Droid/library_project_imports/res
> 	-S /Users/jon/Downloads/bxc-21361/XFormsTest/Android/obj/Debug/__library_projects__/Acr.XamForms.UserDialogs.Droid/library_project_imports/res
> 	-S /Users/jon/Downloads/bxc-21361/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res
> 	-S /Users/jon/Downloads/bxc-21361/XFormsTest/Android/obj/Debug/__library_projects__/Xamarin.Mobile/library_project_imports/res
> 	-S /Users/jon/Downloads/bxc-21361/XFormsTest/Android/obj/Debug/__library_projects__/Xamarin.Mobile/library_project_imports/res
> 	-S /Users/jon/Downloads/bxc-21361/XFormsTest/Android/obj/Debug/__library_projects__/Xamarin.Forms.Platform.Android/library_project_imports/res
> 	-S /Users/jon/Downloads/bxc-21361/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res
> 	-I /opt/android/sdk-tool/sdk/platforms/android-15/android.jar
> 	--no-crunch --auto-add-overlay --max-res-version 15 

Careful reading (and manual testing) shows the *real* problem: AndHud is listed *twice*, and AndHud contains the ahTextColor and related attributes:

> 	-S /Users/jon/Downloads/bxc-21361/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res
> ...
> 	-S /Users/jon/Downloads/bxc-21361/XFormsTest/Android/obj/Debug/__library_projects__/AndHUD/library_project_imports/res

The bug is that $(LibraryResourceDirectories) contains duplicates.
Comment 46 Jonathan Pryor 2014-09-09 12:26:01 UTC
$(LibraryResourceDirectories) contains duplicates because "@(ReferencePath);@(ReferenceDependencyPaths)" contains duplicates; AndHUD.dll is listed twice within diagnostic output.
Comment 47 Jonathan Pryor 2014-09-09 12:37:51 UTC
Fixed in monodroid/5ad2f278.
Comment 48 Kevin Ford 2014-09-10 08:57:20 UTC
Thanks, is this in the Alpha channel yet?
Comment 49 Jonathan Pryor 2014-09-10 10:57:19 UTC
@Kevin: No.
Comment 50 Michael Henke 2014-09-17 16:07:33 UTC
I have the same issue...

Xamarin Studio
Version 5.4 (build 239)
Xamarin.Android
Version: 4.16.0 (Business Edition)

Where to find the fix?
Comment 51 Benoit Jadinon 2014-09-21 10:14:52 UTC
hi, @Jonathan, now that this problam has made its way to the stable release, it is getting really invalidating, 
any idea when this will be released in alpha ?
thanks
Comment 52 Ali Özgür 2014-09-21 16:55:10 UTC
Same problem here. Using Xamarin Studio 5.4 (Build 240)
Comment 53 Brendan Zagaeski (Xamarin Team, assistant) 2014-09-23 02:09:36 UTC
## Possible way to work around the problem while waiting for the fix to be published

The following steps stopped the error for me in the test case from comment 20.

1. Open the Android app `.csproj` file in a text editor. For example, you can Control-click the project in the Xamarin Studio Solution Pad and select "Tools -> Edit File".

2. Find the `<Reference Include=... > ... </Reference>` element for the library project that appears in the error messages.

3. Move that whole `<Reference Include=... > ... </Reference>` element to make it the first item in the enclosing `<ItemGroup>`.
Comment 54 Fixicar Team 2014-09-23 02:21:01 UTC
Guys, I have found a way how to solve this issue temporary.

In your Xamarin Studio, under the Android project expand the "References"/"From Packages" folder, do the right click on Xamarin.Forms.Labs libraries and check the "Specific version" checkbox. 

After these actions my solution was able to build.
Comment 55 web 2014-09-23 05:09:36 UTC
Comment #53 worked for me. Thank you.
Comment 56 Ali Özgür 2014-09-23 08:33:07 UTC
Comment #53 worked for me as well. Thanks Brendan.
Comment 57 Jonathan Pryor 2014-09-23 11:45:43 UTC
Fixed cherry-picked as monodroid-4.18-series/04399d62, and will be present in a future 4.18 beta release.
Comment 58 Benoit Jadinon 2014-09-23 14:20:57 UTC
Thanks @Jonathan.
... and commenters for the quick fix.
Comment 59 Andy Hopper 2014-09-23 21:03:37 UTC
Huzzah! [Comment #53][1] also worked for me.

[1]: https://bugzilla.xamarin.com/show_bug.cgi?id=21361#c53
Comment 62 Rajneesh Kumar 2015-05-05 13:43:28 UTC
I have checked this issue and observed that this issue does't exist now. To verify this issue i have used the attached project in comment 20.And I am able to build and run the project successfully, without ant error or exception.

Here is the screencast for the same: http://www.screencast.com/t/DTNWc8LQ6

This issue has been fixed, hence I am closing this issue.

Thanks..!

Environment Info:

=== Xamarin Studio ===

Version 5.9 (build 464)
Installation UUID: fd157f48-7924-4d8e-b8a8-845aaad94233
Runtime:
	Microsoft .NET 4.0.30319.18408
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.26

=== Xamarin.Android ===

Version: 5.1.0 (Business Edition)
Android SDK: E:\android-sdk
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_39
java version "1.6.0_39"
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) Client VM (build 20.14-b01, mixed mode)

=== Xamarin Android Player ===

Version: 0.3.5
Location: C:\Program Files\Xamarin Android Player\DeviceManager.exe

=== Build Information ===

Release ID: 509000464
Git revision: 97f3c43266a4abe2dff0a31b1afb976de897d099
Build date: 2015-05-04 07:57:21-04
Xamarin addins: 438f3e4b8352e006958552de07c6f54770c9233c

=== Operating System ===

Windows 6.2.9200.0 (64-bit)