You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[net6] Building an application can sometimes cause Xamarin.Android.Tasks.TypeMapGenerator.GenerateRelease to fail #7302
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
@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 .binlog is from VS, and doesn't have the .csproj in it) Do you know if a specific NuGet package causes it?
I think you would hit this with Release builds only.
So the fix is definitely better, but we hit ~606 XA4215 errors now, such as:
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.
Likely due to having multiple Xamarin.AndroidX.Activity.dll when building a net6.0-android MAUI app with .NET 7:
@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 TrimmerRemoveSymbols=true in your project, does it work around the problem?
Activity
grendello commentedon Sep 1, 2022
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?
jeromelaban commentedon Sep 1, 2022
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?
grendello commentedon Sep 1, 2022
@jeromelaban https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/InstallBuildsFromMain.md should help!
jonathanpeppers commentedon Sep 1, 2022
@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
.binlogis from VS, and doesn't have the.csprojin it) Do you know if a specific NuGet package causes it?I think you would hit this with Release builds only.
jonathanpeppers commentedon Sep 6, 2022
I can reproduce this when building a .NET 6 MAUI app with a .NET 7 SDK, it appears to be hitting this line:
https://github.com/xamarin/xamarin-android/blob/863cfc540e97134ad6a8875eae31007ec39889ce/src/Xamarin.Android.Build.Tasks/Utilities/TypeMapGenerator.cs#L395
https://github.com/xamarin/xamarin-android/blob/d6224ca6b1032ffebc8fe2b496f93a511b0674a6/src/Xamarin.Android.Build.Tasks/Utilities/TypeMapGenerator.cs#L385
@grendello can we just change this collection to a
List<T>? Then we should probably also backport this change to .NET 6.jeromelaban commentedon Sep 6, 2022
@jonathanpeppers I don't recall exactly in which context that could happen, but it seems you've found a way to repro it :) Thanks!
Don't use Dictionary<K,V> to avoid duplicate value exception
Don't use Dictionary<K,V> to avoid duplicate value exception (#7340)
Don't use Dictionary<K,V> to avoid duplicate value exception (dotnet#…
Don't use Dictionary<K,V> to avoid duplicate value exception (#7345)
jonathanpeppers commentedon Sep 7, 2022
So the fix is definitely better, but we hit ~606
XA4215errors now, such as:Likely due to having multiple
Xamarin.AndroidX.Activity.dllwhen building anet6.0-androidMAUI app with .NET 7:Normally, these would be reduced to a single assembly.
[illink] set `$(TrimmerRemoveSymbols)` by default
jonathanpeppers commentedon Sep 9, 2022
@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
TrimmerRemoveSymbols=truein your project, does it work around the problem?[illink] set `$(TrimmerRemoveSymbols)` by default (#7365)
jeromelaban commentedon Sep 15, 2022
@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.