Skip to content

Type kotlinx.serialization.BinaryFormat is defined multiple times #1068

Closed

Description

@jethro-djan

Android framework version

net9.0-android

Affected platform version

.NET 9.0.101

Description

I am trying to compile a Xamarin.android project which was recently converted to .NET MAUI using the upgrade-assistant and making all the necessary changes in files and .csproj.

I suddenly started having issues with the dependencies so I decided to upgrade all of them to the latest versions. I resolved all the issues associated to this #764 but I can't fix this one.

It seems to me that MAUI crucially depends on xamarin.android.jetbrains.kotlinx_serialization_core_jvm version 1.3.1. However, some packages in my project also depend on Xamarin.KotlinX.Serialization.Core.Jvm version 1.7.3.1. The class in question is defined in both.

How do I resolve this? I can't remove either without errors.

Relevant log output

`
0>: Error JAVA0000 java: Error in /Users/[user]/.nuget/packages/xamarin.android.jetbrains.kotlinx_serialization_core_jvm/1.3.1/buildTransitive/../jar/org.jetbrains.kotlinx.kotlinx-serialization-core-jvm.jar:kotlinx/serialization/BinaryFormat.class:
Type kotlinx.serialization.BinaryFormat is defined multiple times: /Users/[user]/.nuget/packages/xamarin.android.jetbrains.kotlinx_serialization_core_jvm/1.3.1/buildTransitive/../jar/org.jetbrains.kotlinx.kotlinx-serialization-core-jvm.jar:kotlinx/serialization/BinaryFormat.class, obj/Debug/net9.0-android/lp/679/jl/libs/623E6E29E2058512.jar:kotlinx/serialization/BinaryFormat.class
Compilation failed
java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: /Users/[user]/.nuget/packages/xamarin.android.jetbrains.kotlinx_serialization_core_jvm/1.3.1/buildTransitive/../jar/org.jetbrains.kotlinx.kotlinx-serialization-core-jvm.jar
kotlinx/serialization/BinaryFormat.class
	at com.android.tools.r8.internal.to.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:131)
	at com.android.tools.r8.D8.main(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:5)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: /Users/[user]/.nuget/packages/xamarin.android.jetbrains.kotlinx_serialization_core_jvm/1.3.1/buildTransitive/../jar/org.jetbrains.kotlinx.kotlinx-serialization-core-jvm.jar:kotlinx/serialization/BinaryFormat.class
	at Version.fakeStackEntry(Version_8.5.35.java:0)
	at com.android.tools.r8.T.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:5)
	at com.android.tools.r8.internal.to.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:82)
	at com.android.tools.r8.internal.to.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:32)
	at com.android.tools.r8.internal.to.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:31)
	at com.android.tools.r8.internal.to.b(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:2)
	at com.android.tools.r8.D8.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:41)
	at com.android.tools.r8.D8.b(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:13)
	at com.android.tools.r8.D8.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:39)
	at com.android.tools.r8.internal.to.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:118)
	... 1 more
Caused by: com.android.tools.r8.internal.g: Type kotlinx.serialization.BinaryFormat is defined multiple times: /Users/[user]/.nuget/packages/xamarin.android.jetbrains.kotlinx_serialization_core_jvm/1.3.1/buildTransitive/../jar/org.jetbrains.kotlinx.kotlinx-serialization-core-jvm.jar:kotlinx/serialization/BinaryFormat.class, obj/Debug/net9.0-android/lp/679/jl/libs/623E6E29E2058512.jar:kotlinx/serialization/BinaryFormat.class
	at com.android.tools.r8.internal.x50.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:21)
	at com.android.tools.r8.internal.LY.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:54)
	at com.android.tools.r8.internal.LY.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:10)
	at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2056)
	at com.android.tools.r8.internal.LY.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:6)
	at com.android.tools.r8.graph.p4$a.d(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:6)
	at com.android.tools.r8.dex.c.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:95)
	at com.android.tools.r8.dex.c.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:44)
	at com.android.tools.r8.dex.c.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:9)
	at com.android.tools.r8.D8.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:44)
	at com.android.tools.r8.D8.d(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:17)
	at com.android.tools.r8.D8.c(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:73)
	at com.android.tools.r8.internal.to.a(R8_8.5.35_9c55004e7c41a17b1ed47c4e1952cb6778b3dac6afb6afc113a2737c3cde13e0:28)
	... 6 more
Directory 'obj/Debug/net9.0-android/lp/679' is from 'Xamarin.KotlinX.Serialization.Core.Jvm.aar'.

Activity

  1. moljac commented on Jan 2, 2025

    @moljac
    Contributor

    Thanks for the feedback.

    Please see:

    #764

    Otherwise provide list of PackageReferences so we can investigate.

  2. moljac commented on Jan 2, 2025

    @moljac
    Contributor

    OK I just saw

    I suddenly started having issues with the dependencies so I decided to upgrade all of them to the latest versions. I resolved all the issues associated to this #764 but I can't fix this one.

    Yes it is very problem (app) specific - dependencies, transitive dependencies.

  3. jethro-djan commented on Jan 2, 2025

    @jethro-djan
    Author

    So I tracked it down to removing Microsoft.Maui.Controls. Then I reverted some of the packages back to previous versions that don't depend on Serialization.Core. Then I could safely remove Xamarin.KotlinX.Serialization.Core.Jvm version 1.7.3.1. Now I am unable to compile due to another error (which I don't think is related to this but would appreciate any pointers as to how to resolve).

    NuGet package '<unknown>' version '<unknown>' contains a shared library 'libavutil.so' which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details
    

    The particular library that is not correctly aligned keeps changing.

    Or could it be that removing the package caused this?

  4. moljac commented on Jan 2, 2025

    @moljac
    Contributor

    Error

    NuGet package '' version '' contains a shared library 'libavutil.so' which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details

    is very different from

    Type T is defined multiple times

    where T in your case is kotlinx.serialization.BinaryFormat

    1st one is Warning for now:

    https://learn.microsoft.com/en-us/dotnet/android/messages/xa0141

    Android uses 4kB pages and in the future it will be 16 kB. This warning is for authors of nugets that have native shared (*.so) libraries which will be need recompilation with 16 kB page size.

  5. jpobst commented on Jan 17, 2025

    @jpobst
    Contributor

    It seems to me that MAUI crucially depends on xamarin.android.jetbrains.kotlinx_serialization_core_jvm version 1.3.1.

    It should also be noted that https://www.nuget.org/packages/Xamarin.Android.JetBrains.KotlinX_Serialization_Core_Jvm is not a Microsoft package and I highly doubt MAUI itself depends on it. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions