TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
220 stars 49 forks source link

[Firestore] Exception when updating AndroidX to latest version #222

Closed tranb3r closed 1 year ago

tranb3r commented 1 year ago

When updating Xamarin.AndroidX.Core to the latest version 1.12.0.2, I get the following exception when using Firestore:

System.TypeLoadException: Could not resolve type with token 0100007d from typeref (expected class 'AndroidX.Collection.ArrayMap' in assembly 'Xamarin.AndroidX.Collection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null')
    at Plugin.Firebase.Firestore.Platforms.Android.Extensions.JavaObjectExtensions.Cast(IDictionary this, Type targetType, String documentId)
    at Plugin.Firebase.Firestore.Platforms.Android.Extensions.JavaObjectExtensions.Cast[SyncDocument](IDictionary`2 this, String documentId)
    at Plugin.Firebase.Firestore.Platforms.Android.DocumentSnapshotWrapper`1[[MySyncDocument, ...]].get_Data()

The problem is that I have to update Xamarin.AndroidX.Collection for my project to build when updating Xamarin.AndroidX.Core:

<PackageReference Include="Xamarin.AndroidX.Core" Version="1.12.0.2" />
<PackageReference Include="Xamarin.AndroidX.Collection" Version="1.3.0.1" />
<PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.3.0.1" />

And it seems there a change in Xamarin.AndroidX.Collection that is not compatible with the current version of the your plugin when using AndroidX.Collection.ArrayMap.

Can this exception be fixed? Is there a plan to support new versions or AndroidX?

TobiasBuchholz commented 1 year ago

Yes, new versions of AndroidX should be supported and it would be great if you could create an example project that demonstrates this issue. Thanks! :)

tranb3r commented 1 year ago

@TobiasBuchholz Here is a repro project. It's really simple. When clicking on the button, an alert dialog appears with the exception message. If you remove the AndroidX update block from the csproj, everything is fine.

TobiasBuchholz commented 1 year ago

Hi @tranb3r, thanks for the repro project!

It seems like updating the underlying Xamarin.Firebase.Firestore package from version 124.3.1 to the newest version 124.8.1.1 solves your issue. After doing that the sample and test projects are not building anymore though, so maybe now is the best time to update those projects to .net7 or even .net8. I don't know when I have the time for doing that, so in the meantime you could download the source code and reference the 'updated' Firestore project yourself.

tranb3r commented 1 year ago

I tried to update Xamarin.Firebase.Firestore in my app (not the simple repro), but then another error pops up, this time preventing the app from starting:

[MonoDroid] java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/appcheck/interop/InternalAppCheckTokenProvider;
[MonoDroid]     at com.google.firebase.storage.StorageRegistrar.getComponents(StorageRegistrar.java:38)
[MonoDroid]     at com.google.firebase.tracing.ComponentMonitor.processRegistrar(ComponentMonitor.java:28)
[MonoDroid]     at com.google.firebase.components.ComponentRuntime.discoverComponents(ComponentRuntime.java:118)
[MonoDroid]     at com.google.firebase.components.ComponentRuntime.<init>(ComponentRuntime.java:100)
[MonoDroid]     at com.google.firebase.components.ComponentRuntime.<init>(ComponentRuntime.java:46)
[MonoDroid]     at com.google.firebase.components.ComponentRuntime$Builder.build(ComponentRuntime.java:407)
[MonoDroid]     at com.google.firebase.FirebaseApp.<init>(FirebaseApp.java:439)
[MonoDroid]     at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:296)
[MonoDroid]     at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:264)
[MonoDroid]     at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:249)
[MonoDroid]     at com.google.firebase.provider.FirebaseInitProvider.onCreate(FirebaseInitProvider.java:69)
TobiasBuchholz commented 1 year ago

Yes, I had the same issue in my sample and test projects and it turns out updating the native Xamarin.Firebase.Storage package as well as the native Xamarin.Firebase.Functions package is needed. That's done now! I've just released new versions Plugin.Firebase.Firestore 2.0.5, Plugin.Firebase.Functions 2.0.2, Plugin.Firebase.Storage 2.0.2 and Plugin.Firebase 2.0.7. I've also updated the sample and test projects to use .net7...was easier than expected :)

If there are no other problems feel free to close this issue.

tranb3r commented 1 year ago

The issue is fixed with the new release. Thanks a lot!