I'm working on a C# native android project using net8.0-android34.0 as framework version and one of the projects in the solution imports those android libraries:
<AndroidLibrary Update="Jars\jc3api.jar" />
<AndroidLibrary Update="Jars\jc3api-android.jar" />
<AndroidLibrary Update="Jars\commons-codec-1.6r.jar" Bind="false" />
<AndroidLibrary Update="Jars\gson-2.8.4.jar" Bind="false" />
<AndroidLibrary Update="Jars\jxx-1.4.20.jar" Bind="false" />
<AndroidLibrary Update="Jars\log4j-1.2.15.jar" Bind="false" />
<AndroidLibrary Update="Jars\PclServiceLib_2.04.00.jar" Bind="false" />
<AndroidLibrary Update="Jars\PclUtilities_2.04.00.jar" Bind="false" />
All was working fine, since I added a new .net MAUI project to my solution using the procedure described in this MDSN article to embed it and suddenly the solution is not building anymore...
When I try to build it, compiler throws this exception:
42>MSBUILD : java.exe error JAVA0000: Error in obj\Debug\net8.0-android34.0\lp\166\jl\libs\ED64959F88B22E6D.jar:com/google/gson/FieldNamingPolicy$5.class:
42>MSBUILD : java.exe error JAVA0000: Type com.google.gson.FieldNamingPolicy$5 is defined multiple times:
obj\Debug\net8.0-android34.0\lp\166\jl\libs\ED64959F88B22E6D.jar:com/google/gson/FieldNamingPolicy$5.class,
obj\Debug\net8.0-android34.0\lp\176\jl\libs\10E7DD84A5967575.jar:com/google/gson/FieldNamingPolicy$5.class
42>MSBUILD : java.exe error JAVA0000: Compilation failed
42>MSBUILD : java.exe error JAVA0000: java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj\Debug\net8.0-android34.0\lp\166\jl\libs\ED64959F88B22E6D.jar
42>MSBUILD : java.exe error JAVA0000: com/google/gson/FieldNamingPolicy$5.class
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.utils.S0.a(...:135)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.D8.main(...:5)
42>MSBUILD : java.exe error JAVA0000: Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj\Debug\net8.0-android34.0\lp\166\jl\libs\ED64959F88B22E6D.jar:com/google/gson/FieldNamingPolicy$5.class
42>MSBUILD : java.exe error JAVA0000: at Version.fakeStackEntry(Version_8.2.33.java:0)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.T.a(...:5)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.utils.S0.a(...:82)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.utils.S0.a(...:32)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.utils.S0.a(...:31)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.utils.S0.b(...:2)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.D8.a(...:42)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.D8.b(...:13)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.D8.a(...:40)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.utils.S0.a(...:122)
42>MSBUILD : java.exe error JAVA0000: ... 1 more
42>MSBUILD : java.exe error JAVA0000: Caused by: com.android.tools.r8.utils.b: Type com.google.gson.FieldNamingPolicy$5 is defined multiple times:
obj\Debug\net8.0-android34.0\lp\166\jl\libs\ED64959F88B22E6D.jar:com/google/gson/FieldNamingPolicy$5.class,
obj\Debug\net8.0-android34.0\lp\176\jl\libs\10E7DD84A5967575.jar:com/google/gson/FieldNamingPolicy$5.class
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.utils.Q2.a(...:21)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.utils.D2.a(...:54)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.utils.D2.a(...:10)
42>MSBUILD : java.exe error JAVA0000: at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2056)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.utils.D2.a(...:6)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.graph.m4$a.d(...:6)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.dex.c.a(...:61)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.dex.c.a(...:12)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.dex.c.a(...:9)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.D8.a(...:45)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.D8.d(...:17)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.D8.c(...:69)
42>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.utils.S0.a(...:28)
42>MSBUILD : java.exe error JAVA0000: ... 6 more
42>MSBUILD : java.exe error JAVA0000: Directory 'obj\Debug\net8.0-android34.0\lp\166' is from 'GoogleGson.aar'.
I already tried all the fast solutions, such as clean and rebuild, or delete manually all bin/obj folders, restart vs and then rebuild but no one of this tries succeeded...
I also tried to install GoogleGson nuget package directly in my main project but this haven't solved the issue...
My best try was this post on github which seems to explain a possible solution, but I don't know how to implement it in a C# project
Thank you in advance to anyone which could help me, I've been stuck on that issue for the whole morning and my head is very close to explode!
ED64959F88B22E6D.jarand10E7DD84A5967575.jarrefer to? I assume your C# build assigned these identifiers, but I am not familiar with C# at all. It looks a bit as if one of your dependencies includes the Gson classes itself. You could maybe solve this by omitting theJars\gson-2.8.4.jarentry, but the better solution might be to find the other dependency which includes the Gson classes and see if there is another variant of it which does not include the Gson classes.