F.A.Q
This document answers the following frequently asked questions:
Duplicated classes compile error for Android
It can happen that, on compile time, you get error messages regarding duplicated classes. MAUI is more prone for these kind of errors due to the way Android dependencies are managed.
These kind of errors look like this:
>: Error JAVA0000 java: Error in obj/Debug/net8.0-android/lp/142/jl/classes.jar:androidx/activity/ActivityViewModelLazyKt$viewModels$1.class:
Type androidx.activity.ActivityViewModelLazyKt$viewModels$1 is defined multiple times: obj/Debug/net8.0-android/lp/142/jl/classes.jar:androidx/activity/ActivityViewModelLazyKt$viewModels$1.class, obj/Debug/net8.0-android/lp/175/jl/classes.jar:androidx/activity/ActivityViewModelLazyKt$viewModels$1.class
Compilation failed
java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj/Debug/net8.0-android/lp/142/jl/classes.jar
androidx/activity/ActivityViewModelLazyKt$viewModels$1.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/142/jl/classes.jar:androidx/activity/ActivityViewModelLazyKt$viewModels$1.class
at Version.fakeStackEntry(Version_8.1.56.java:0)
at com.android.tools.r8.M.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:5)
... snip
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 androidx.activity.ActivityViewModelLazyKt$viewModels$1 is defined multiple times: obj/Debug/net8.0-android/lp/142/jl/classes.jar:androidx/activity/ActivityViewModelLazyKt$viewModels$1.class, obj/Debug/net8.0-android/lp/175/jl/classes.jar:androidx/activity/ActivityViewModelLazyKt$viewModels$1.class
at com.android.tools.r8.utils.O2.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:21)
... snip
at com.android.tools.r8.utils.R0.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:28)
... 6 more
Directory 'obj/Debug/net8.0-android/lp/142' is from 'androidx.activity.activity.aar'.
During compile time, MAUI grabs all classes.dex from the jar/aar files, put them in a numberic folder and then compiles them. You can see in the first part of the error message where these files are located:
obj/Debug/net8.0-android/lp/142/jl/classes.jar
At the end of the error message it will tell you from which package the error came:
Directory 'obj/Debug/net8.0-android/lp/142' is from 'androidx.activity.activity.aar'.
There are a couple of ways to solve these issues when you encounter them, please check the Github issue for Xamarin.AndroidX