android.netxamarin.formsmauiandroidx

.NET MAUI Android app not building due to Java error related to AndroidX dependencies


I'm migrating a Xamarin.Forms app into .NET MAUI and after fixing various issues and errors, last of which was solved by adding two references:

as suggested here, which seemed to help solve a very similar looking JAVA error, but made another pop up:

Error   JAVA0000    Error in obj\Debug\net8.0-android\lp\141\jl\classes.jar:android/support/v4/app/INotificationSideChannel$Stub.class:
Type android.support.v4.app.INotificationSideChannel$Stub is defined multiple times: obj\Debug\net8.0-android\lp\141\jl\classes.jar:android/support/v4/app/INotificationSideChannel$Stub.class, obj\Debug\net8.0-android\lp\28\jl\bin\classes.jar:android/support/v4/app/INotificationSideChannel$Stub.class
Compilation failed
java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj\Debug\net8.0-android\lp\141\jl\classes.jar
android/support/v4/app/INotificationSideChannel$Stub.class
    at com.android.tools.r8.utils.R0.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:126)
    at com.android.tools.r8.D8.main(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:5)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj\Debug\net8.0-android\lp\141\jl\classes.jar:android/support/v4/app/INotificationSideChannel$Stub.class
    at Version.fakeStackEntry(Version_8.1.56.java:0)
    at com.android.tools.r8.M.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:5)
    at com.android.tools.r8.utils.R0.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:81)
    at com.android.tools.r8.utils.R0.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:32)
    at com.android.tools.r8.utils.R0.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:31)
    at com.android.tools.r8.utils.R0.b(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:2)
    at com.android.tools.r8.D8.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:26)
    at com.android.tools.r8.D8.b(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:13)
    at com.android.tools.r8.D8.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:24)
    at com.android.tools.r8.utils.R0.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:113)
    ... 1 more
Caused by: com.android.tools.r8.utils.b: Type android.support.v4.app.INotificationSideChannel$Stub is defined multiple times: obj\Debug\net8.0-android\lp\141\jl\classes.jar:android/support/v4/app/INotificationSideChannel$Stub.class, obj\Debug\net8.0-android\lp\28\jl\bin\classes.jar:android/support/v4/app/INotificationSideChannel$Stub.class
    at com.android.tools.r8.utils.O2.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:21)
    at com.android.tools.r8.utils.O2.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:26)
    at com.android.tools.r8.utils.A2.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:44)
    at com.android.tools.r8.utils.A2.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:10)
    at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2056)
    at com.android.tools.r8.utils.A2.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:6)
    at com.android.tools.r8.graph.b4$a.e(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:7)
    at com.android.tools.r8.dex.c.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:58)
    at com.android.tools.r8.dex.c.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:9)
    at com.android.tools.r8.dex.c.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:8)
    at com.android.tools.r8.D8.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:29)
    at com.android.tools.r8.D8.d(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:17)
    at com.android.tools.r8.D8.c(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:1)
    at com.android.tools.r8.utils.R0.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:28)
    ... 6 more
Directory 'obj\Debug\net8.0-android\lp\141' is from 'androidx.core.core.aar'.   ARC.Mobile.Android      1   

The very end of the error suggests still an issue with AndroidX dependencies, but I'm fairly clueless here.

EDIT: My package references are as follows:

<PackageReference Include="CommunityToolkit.Maui.Markup" Version="4.0.0" />
<PackageReference Include="Controls.UserDialogs.Maui" Version="1.5.4" />
<PackageReference Include="IdentityModel.OidcClient" Version="6.0.0" />
<PackageReference Include="Syncfusion.Maui.Core" Version="26.1.35" />
<PackageReference Include="Xamarin.AndroidX.Collection" Version="1.4.0.4" />
<PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.4.0.3" />
<PackageReference Include="Xamarin.Azure.NotificationHubs.Android" Version="1.1.4.1" />
<PackageReference Include="Xamarin.Google.Dagger" Version="2.49.0.1" />
<PackageReference Include="Xamarin.GooglePlayServices.Base" Version="118.3.0.1" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.40" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.40" />

Solution

  • This is sticky issue where different cases are kept, so users can get a feeling how work around this class of issues:

    https://github.com/xamarin/AndroidX/issues/764

    In your case try explicitly adding:

    <PackageReference Include="Xamarin.AndroidX.Core" Version="1.13.1.1" />
    <PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.25" />
    

    If that does not help I will need list of your PaxkageReferences