-
Notifications
You must be signed in to change notification settings - Fork 533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[net6] Building an application can sometimes cause Xamarin.Android.Tasks.TypeMapGenerator.GenerateRelease
to fail
#7302
Comments
This is most likely fixed by dotnet/runtime#67660, would you be able to test your application with a NET7 preview build of Xamarin.Android? |
I could do that. I was under the impression that net7 builds were not ready to be used, but is there a guide to do this kind of testing? |
@jeromelaban if you are hitting this in .NET 6 with the .NET 6 SDK, can you give some more details about the project you got this error? (I think the I think you would hit this with Release builds only. |
I can reproduce this when building a .NET 6 MAUI app with a .NET 7 SDK, it appears to be hitting this line: @grendello can we just change this collection to a |
@jonathanpeppers I don't recall exactly in which context that could happen, but it seems you've found a way to repro it :) Thanks! |
Fixes: dotnet#7302 Context: dotnet@7117414 When building .NET6 app on .NET7, sometimes the build fails with: C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.451\tools\Xamarin.Android.Common.targets(1438,3): error XAGJS7004: System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Xamarin.Android.Tasks.TypeMapGenerator.GenerateRelease(Boolean skipJniAddNativeMethodRegistrationAttributeScan, List`1 javaTypes, String outputDirectory, ApplicationConfigTaskState appConfState) at Xamarin.Android.Tasks.GenerateJavaStubs.WriteTypeMappings(List`1 types, TypeDefinitionCache cache) at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 Avoid that by switching the data structure to `List<T>`, since we no longer use the Dictionary key for anything.
Fixes: #7302 Context: 7117414 When building .NET6 app on .NET7, sometimes the build fails with: C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.451\tools\Xamarin.Android.Common.targets(1438,3): error XAGJS7004: System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Xamarin.Android.Tasks.TypeMapGenerator.GenerateRelease(Boolean skipJniAddNativeMethodRegistrationAttributeScan, List`1 javaTypes, String outputDirectory, ApplicationConfigTaskState appConfState) at Xamarin.Android.Tasks.GenerateJavaStubs.WriteTypeMappings(List`1 types, TypeDefinitionCache cache) at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 Avoid that by switching the data structure to `List<T>`, since we no longer use the Dictionary key for anything.
…7340) Fixes: dotnet#7302 Context: dotnet@7117414 When building .NET6 app on .NET7, sometimes the build fails with: C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.451\tools\Xamarin.Android.Common.targets(1438,3): error XAGJS7004: System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Xamarin.Android.Tasks.TypeMapGenerator.GenerateRelease(Boolean skipJniAddNativeMethodRegistrationAttributeScan, List`1 javaTypes, String outputDirectory, ApplicationConfigTaskState appConfState) at Xamarin.Android.Tasks.GenerateJavaStubs.WriteTypeMappings(List`1 types, TypeDefinitionCache cache) at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 Avoid that by switching the data structure to `List<T>`, since we no longer use the Dictionary key for anything.
Fixes: #7302 Context: 7117414 When building .NET6 app on .NET7, sometimes the build fails with: C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.451\tools\Xamarin.Android.Common.targets(1438,3): error XAGJS7004: System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Xamarin.Android.Tasks.TypeMapGenerator.GenerateRelease(Boolean skipJniAddNativeMethodRegistrationAttributeScan, List`1 javaTypes, String outputDirectory, ApplicationConfigTaskState appConfState) at Xamarin.Android.Tasks.GenerateJavaStubs.WriteTypeMappings(List`1 types, TypeDefinitionCache cache) at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 Avoid that by switching the data structure to `List<T>`, since we no longer use the Dictionary key for anything. Co-authored-by: Marek Habersack <[email protected]>
So the fix is definitely better, but we hit ~606
Likely due to having multiple
Normally, these would be reduced to a single assembly. |
Fixes: dotnet#7302 Context: dotnet/linker#2203 Context: dotnet/runtime#67660 Context: dotnet#6598 This partially backports 745214d. In addition to this backport to dotnet/runtime/release/6.0: dotnet/runtime#75311 We also have another change in .NET 7 that opts into `$(TrimmerRemoveSymbols)` by default for `Release` builds. This allows the .NET 7 linker to have stable MVIDs for assemblies for each architecture. There may potentially be a dotnet/linker issue here to look into further. However, this seems to be the best fix for getting .NET 6 projects building under .NET 7 at the moment.
@jeromelaban we've been working on this issue a bit more. I think #7365 solves the underlying issue. (although we might also need dotnet/runtime#75311) If you set |
Fixes: #7302 Context: dotnet/linker#2203 Context: dotnet/runtime#67660 Context: #6598 This partially backports 745214d. Building a `net6.0-android` app in `Release` mode with .NET 7 can fail with many errors like: error XA4215: The Java type `androidx.activity.contextaware.OnContextAvailableListener` is generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted. This happens because we end up with multiple assemblies, such as: obj/Release/net6.0-android/android-arm/linked/Xamarin.AndroidX.Activity.dll obj/Release/net6.0-android/android-arm64/linked/Xamarin.AndroidX.Activity.dll obj/Release/net6.0-android/android-x64/linked/Xamarin.AndroidX.Activity.dll obj/Release/net6.0-android/android-x86/linked/Xamarin.AndroidX.Activity.dll To fix this, in addition to this backport to dotnet/runtime/release/6.0: dotnet/runtime#75311 In .NET 7 we opt into `$(TrimmerRemoveSymbols)` by default for `Release` builds. This allows the .NET 7 linker to have stable MVIDs for assemblies for each architecture. Somehow when the linker outputs `.pdb` files, it creates different MVIDs per architecture. There may potentially be a dotnet/linker issue here to look into further. However, this seems to be the best fix for getting .NET 6 projects building under .NET 7 at the moment.
@jonathanpeppers I have not seen that issue again recently, knowing the workaround of rebuilding but I'll be on the lookout and try your workaround. |
Android application type
Android for .NET (net6.0-android, etc.)
Affected platform version
17.3.0
Description
Building an app can sometimes cause this:
Steps to Reproduce
Did you find any workaround?
Cleaning bin/obj folders.
Relevant log output
android-build-failure.zip
The text was updated successfully, but these errors were encountered: