xamarin / AndroidX

AndroidX bindings for .NET for Android
MIT License
173 stars 42 forks source link

Fix duplicate DataStore.Core.[Android|Jvm] code. #906

Closed jpobst closed 23 hours ago

jpobst commented 1 week ago

Fixes: https://github.com/xamarin/GooglePlayServicesComponents/issues/880

If you try to consume the package Xamarin.AndroidX.DataStore.Preferences, you get the following error:

JAVA0000: Error in C:\.tools\.nuget\packages\xamarin.androidx.datastore.core.jvm\1.1.1.2\buildTransitive\net8.0-android34.0\..\..\jar\androidx.datastore.datastore-core-jvm.jar:androidx/datastore/core/Actual_jvmKt.class:
JAVA0000: Type androidx.datastore.core.Actual_jvmKt is defined multiple times: 
- C:\.tools\.nuget\packages\xamarin.androidx.datastore.core.jvm\1.1.1.2\buildTransitive\net8.0-android34.0\..\..\jar\androidx.datastore.datastore-core-jvm.jar:androidx/datastore/core/Actual_jvmKt.class, 
- obj\Release\net8.0-android\lp\30\jl\classes.jar:androidx/datastore/core/Actual_jvmKt.class

This is because through the complex set of dependencies, you end up using these 2 packages:

These packages contain the same Java code, the Android one seems to be a superset of the Jvm one:

image

Thus we believe the solution is to redirect the Jvm package to the Android one. That is, anytime the Jvm package is requested we are going to give it the Android one instead.

We will accomplish this via:

With these changes, we no longer see the conflict errors when consuming the Xamarin.AndroidX.DataStore.Preferences* packages in the ExtendedTests suite.

Additionally, bump all the androidx.datastore packages so that this new version will get picked up.