Is the package Xamarin.Firebase.Common
supposed to be able to get installed on the shared Xamarin project?
I try to install it, but I get an error:
Error NU1202 Package Xamarin.Firebase.Common 120.1.0.1 is not
compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package
Xamarin.Firebase.Common 120.1.0.1 supports:
- monoandroid12.0 (MonoAndroid,Version=v12.0)
- net6.0-android31.0 (.NETCoreApp,Version=v6.0)
Both Target Framework
and Target Android Version
are set to Android 13
for the Android project.
2
Answers
Just as ewerspej said, you need to install the Xamarin.Firebase.Common pakcage in the xamarin.forms project’s android part.
And then, you can create a class in the android part and use the
FirebaseNetworkException
in the class’s method. After that, you can use the dependency service to call the method in the shared Xamarin project.For more information, you can refer to the official document about the Xamarin.Forms DependencyService Introduction.
First of all, you cannot use the
Xamarin.Firebase.Common
package, which has a dependency on Android, in the shared project of your Xamarin.Forms app.Secondly, you cannot use native exceptions in the shared, cross-platform context. Therefore, you won’t have access to
FirebaseNetworkException
, etc. in the shared project.Instead, since you’re already using the Plugin.FirebaseAuth, you need to catch
FirebaseAuthException
instead, which wraps the different platform-specific exceptions and hides them behind error codes.Your code should be looking something like this:
There’s a full list for the mapping of the
ErrorType
enum to the Firebase exceptions in the documentation.Therefore, wherever you need to catch an exception, you can check the
ErrorType
and perform the appropriate operation or show an error message to the user.