Plugin.Firebase 3.1.1

dotnet add package Plugin.Firebase --version 3.1.1                
NuGet\Install-Package Plugin.Firebase -Version 3.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Plugin.Firebase" Version="3.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Plugin.Firebase --version 3.1.1                
#r "nuget: Plugin.Firebase, 3.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Plugin.Firebase as a Cake Addin
#addin nuget:?package=Plugin.Firebase&version=3.1.1

// Install Plugin.Firebase as a Cake Tool
#tool nuget:?package=Plugin.Firebase&version=3.1.1                

Plugin.Firebase

This is a wrapper library around the native Android and iOS Firebase Xamarin SDKs which includes cross-platform APIs for most of the Firebase features.

Supported features

Feature Plugin Version
Analytics Plugin.Firebase.Analytics NuGet
Auth Plugin.Firebase.Auth NuGet
Facebook Sign In Plugin.Firebase.Auth.Facebook NuGet
Google Sign In Plugin.Firebase.Auth.Google NuGet
Cloud Messaging Plugin.Firebase.CloudMessaging NuGet
Crashlytics Plugin.Firebase.Crashlytics NuGet
Dynamic Links Plugin.Firebase.DynamicLinks NuGet
Firestore Plugin.Firebase.Firestore NuGet
Cloud Functions Plugin.Firebase.Functions NuGet
Remote Config Plugin.Firebase.RemoteConfig NuGet
Storage Plugin.Firebase.Storage NuGet
All in one Plugin.Firebase NuGet

Version 3.0.0 Notes

Version 3.0.0 of this plugin marks a migration from the abandoned Microsoft-published Firebase iOS Nuget packages (prefixed with Xamarin.Firebase.iOS.* this plugin previously depended on.

Public discussion of the issue can be found on MAUI's GH

There should not be any breaking API changes. However, we felt the major version bump was appropriate to communicate the significant change in the plugin's iOS binding dependencies, which are no longer sourced by Microsoft. Moving forward, this plugin will depend on a community-maintained fork of the deprecated packages published under a new package prefix AdamE.Firebase.iOS.*

The migration to AdamE.Firebase.iOS.* packages additionally bumps underlying native Firebase iOS SDKs to version 10.24.0. This is a significant upgrade from the previous latest-available version supported by Microsoft of 8.10. Check the Firebase iOS SDK release notes to see what's changed, which includes various bug fixes as well as privacy manifest support.

Basic setup

  1. Create a Firebase project in the Firebase Console, if you don't already have one. If you already have an existing Google project associated with your mobile app, click Import Google Project. Otherwise, click Create New Project.
  2. Click Add Firebase to your [iOS|Android] app and follow the setup steps. If you're importing an existing Google project, this may happen automatically and you can just download the config file.
  3. Add [GoogleService-Info.plist|google-services.json] file to your app project.
  4. Set [GoogleService-Info.plist|google-services.json] build action behaviour to [Bundle Resource|GoogleServicesJson] by Right clicking/Build Action.
  5. (iOS only) Check the Readme at AdamEssenmacher/GoogleApisForiOSComponents for additional setup steps that may be required.

.NET MAUI support

The new plugin version 1.2.0 now supports .NET MAUI applications with .NET 6 🚀

To get started add the GoogleService-Info.plist and the google-services.json files to the root folder of your project and include them in the .csproj file like this:

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
    <GoogleServicesJson Include="google-services.json" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">
    <BundleResource Include="GoogleService-Info.plist" />
</ItemGroup>

Be sure to change the TargetFramework condition to the correct value for your target versions (i.e. net6.0-*, net7.0-*, net8.0-*, etc.)

Initialize the plugin in your MauiProgram.cs like this:

using Plugin.Firebase.Auth;

#if IOS
using Plugin.Firebase.Core.Platforms.iOS;
#elif ANDROID
using Plugin.Firebase.Core.Platforms.Android;
#endif

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        return MauiApp
            .CreateBuilder()
            .UseMauiApp<App>()
            ...
            .RegisterFirebaseServices()
            .Build();
    }
    
    private static MauiAppBuilder RegisterFirebaseServices(this MauiAppBuilder builder)
    {
        builder.ConfigureLifecycleEvents(events => {
#if IOS
            events.AddiOS(iOS => iOS.WillFinishLaunching((_,__) => {
                CrossFirebase.Initialize();
                return false;
            }));
#elif ANDROID
            events.AddAndroid(android => android.OnCreate((activity, _) =>
                CrossFirebase.Initialize(activity)));
#endif
        });
        
        builder.Services.AddSingleton(_ => CrossFirebaseAuth.Current);
        return builder;
    }
    
}

Ensure the ApplicationId in your .csproj file matches the bundle_id and package_name inside of the [GoogleService-Info.plist|google-services.json] files:

<ApplicationId>com.example.myapp</ApplicationId>

The plugin doesn't support Windows or Mac catalyst, so either remove their targets from your .csproj file or use preprocessor directives and MSBuild conditions, e.g:

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios' OR '$(TargetFramework)' == 'net8.0-android'">
    <PackageReference Include="Plugin.Firebase" Version="1.2.0" />
</ItemGroup>

Android specifics

  • For package versions prior to Plugin.Firebase 2.0.7, Plugin.Firebase.Auth 2.0.5, Plugin.Firebase.Firestore 2.0.5, Plugin.Firebase.Functions 2.0.2 or Plugin.Firebase.Storage 2.0.2 add the following ItemGroup to your .csproj file to prevent build errors:
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
  <PackageReference Include="Xamarin.Kotlin.StdLib.Jdk7" Version="1.7.10" ExcludeAssets="build;buildTransitive" />
  <PackageReference Include="Xamarin.Kotlin.StdLib.Jdk8" Version="1.7.10" ExcludeAssets="build;buildTransitive" />
</ItemGroup>
  • For versions < 3.1.0 add the following ItemGroup to your .csproj file to prevent build errors:
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
    <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" />
    <PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.8.0.1" />
    <PackageReference Include="Xamarin.AndroidX.Browser" Version="1.6.0.2" />
</ItemGroup>
  • For versions >= 3.1.0 that use Plugin.Firebase.Firestore add:
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
    <PackageReference Include="Xamarin.AndroidX.Core" Version="1.15.0.1" />
    <PackageReference Include="Xamarin.AndroidX.Collection" Version="1.4.5.1" />
    <PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.4.5.1" />
    <PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.9.3.1" />
    <PackageReference Include="Xamarin.AndroidX.Browser" Version="1.8.0.7" />
    <PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData.Core" Version="2.8.7.1" />
    <PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData.Core.Ktx" Version="2.8.7.1" />
</ItemGroup>

Take a look at the sample project to get more information.

Plugin.Firebase.Legacy

If you are working with an older Xamarin project and are not able to migrate to .NET MAUI yet, there is a legacy version of the plugin called Plugin.Firebase.Legacy. The code for this package is located on a branch called legacy. Bugfixes or other small important changes can be done here and will be synced to the development/master branch if needed.

Android specifics

  • Add the following PackageReference to the .csproj file of your android project to prevent a build error (see this github comment for more information):
<PackageReference Include="Xamarin.Google.Guava.ListenableFuture" Version="1.0.0.2" ExcludeAssets="build;buildTransitive" />
  • If you receive an error that states the default Firebase App is not initialized, adding one package explicitly seems to resolve this issue (it doesn't seem to matter which package gets added).

Documentation and samples

In the docs folder you can find for every feature a designated readme file that describes the setup and usage of this feature or where to find more information.

In the sample folder you can find a sample Xamarin.Forms project. This project serves as a base to play around with the plugin and to test features that are hard to test automatically (like Authentication or Cloud Messages). playground-functions is a Cloud Functions project and contains the code to enable sending Cloud Messages from the backend.

In the tests folder you can find a Xamarin.Forms project that lets you run integration tests. You should definitely check out the *Fixture.cs files to learn how the plugin is supposed to work. All the tests should pass when they get executed on a real device.

In case you would like to run the sample or test project by yourself, you need to add the GoogleService-Info.plist and google-services.json files of your own firebase project and adapt the other config files like Info.plist, Entitlements.plist, AndroidManifest.xml.

For windows users

@coop-tim has created a .NET 8 sample project with a really good and extensive description. It's targeting iOS and Android with Firebase Cloud Messaging, Analytics and the relevant build pipelines to get them built and pushed into App Center. Definitely worth checking it out!

Using Firebase Local Emulator Suite

If you would like to use the Firebase Local Emulator Suite for your tests or rapid prototyping you can do so by following the steps of the Getting started guide and calling the UseEmulator(host, port) method of the desired firebase service before doing any other operations.

For example the Plugin.Firebase.IntegrationTests project is configured to be able to use the Cloud Firestore emulator. You can start the emulator with initial seed data by running firebase emulators:start --only firestore --import=test-data/. Uncomment the line CrossFirebaseFirestore.Current.UseEmulator("localhost", 8080); in IntegrationTestAppDelegate.cs or MainActivity.cs to let the test project know it should use the emulator. Now all firestore related tests should pass.

Troubleshooting

Windows 11 long path issue

Problems with the Xamarin.Firebase.iOS.Core package mean that installation can fail on Windows due to long paths See dotnet/maui#17828. To combat this, you need to enable long paths in the registry and move your local nuget cache. You should also keep the path to your project as short as possible.:

Powershell

Run in an elevated prompt

New-ItemProperty `
    -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
    -Name "LongPathsEnabled" `
    -Value 1 `
    -PropertyType DWORD `
    -Force
Nuget cache

Create a folder named C:\n. Add an environment variable:

NUGET_PACKAGES = C:\n

Install package !!!manually via CLI!!!

Don't open or build the project in VS until you have done the next part.

Navigate to your project folder and run in a command line:

dotnet add package Xamarin.Firebase.iOS.Core

Additional hints:
  • The long path problem is caused by XCFramework format. These are just naturally going to have long file names.
  • Visual Studio (Windows) is fundamentally not compatible with long file names.
  • There's nothing this plugin can do about it. Issues should be opened with the Visual Studio team and the iOS components team over at https://github.com/xamarin/GoogleApisForiOSComponents (for all the good it'll do you...)
  • This doesn't affect macs, which don't have an issue with the long file names.
  • The plugin is still buildable on VS (Windows) as long as you run dotnet restore outside of the IDE. However, the archiving will probably still need to happen on a mac.

Contributions

You are welcome to contribute to this project by creating a Pull Request. The project contains an .editorconfig file that handles the code formatting, so please apply the formatting rules by running dotnet format src/Plugin.Firebase.sln in the console before creating a Pull Request (see dotnet-format docs or this video for more information).

License

Plugin.Firebase is released under the MIT license. See the LICENSE file for details.

Release notes

  • Version 2.0.*
    • see docs of separate nuget packages
  • Version 2.0.0
    • All features have been split into separate nuget packages
    • Cleaned up namespaces
    • Enable usage of DateTime in Firestore #137
    • Remove unnecessary dependency Microsoft.CSharp #143
    • Fix fcm token refresh by adding DidReceiveRegistrationToken method to FirebaseCloudMessagingImplementation
  • Version 1.3.0
    • Get rid of newtonsoft.json, use system.text.json instead #119
    • Add crashlytics implementation #120
    • Add support for DateTime type to ToHashMap/Put extension #121
    • Lazy google/facebook auth #122
    • Return FIRAuthError.WrongPassword at android for wrong pw signin #117
    • Calling completion in didReceiveNotificationResponse:completionHandler #106
    • Big thanks to tranb3r for the contributions! 😃
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-android34.0 is compatible.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-ios18.0 is compatible.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Plugin.Firebase:

Package Downloads
NeuroSpeech.NativeShell

Package Description

NeuroSpeech.Positron

Package Description

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Plugin.Firebase:

Repository Stars
simpleidserver/SimpleIdServer
OpenID, OAuth 2.0, SCIM2.0, UMA2.0, FAPI, CIBA & OPENBANKING Framework for ASP.NET Core
Version Downloads Last updated
3.1.1 1,344 11/9/2024
3.0.0 22,139 5/29/2024
2.0.14 17,602 5/2/2024
2.0.13 12,434 3/29/2024
2.0.12 15,507 1/24/2024
2.0.11 2,099 1/13/2024
2.0.10 4,088 1/4/2024
2.0.9 5,241 11/22/2023
2.0.8 2,256 11/20/2023
2.0.7 1,042 11/14/2023
2.0.6 6,556 10/18/2023
2.0.5 15,570 7/28/2023
2.0.4 1,920 7/20/2023
2.0.3 19,396 4/27/2023
2.0.2 2,515 4/11/2023
2.0.1 1,970 3/31/2023
2.0.0 3,792 3/26/2023
1.3.0 6,626 1/30/2023
1.2.5 9,167 12/18/2022
1.2.4 1,188 12/12/2022
1.2.3 1,675 11/29/2022
1.2.2 2,049 11/17/2022
1.2.1 2,685 10/26/2022
1.2.0 8,144 9/8/2022
1.1.5 840 9/7/2022
1.1.4 730 8/24/2022
1.1.3 566 8/22/2022
1.1.2 709 7/26/2022
1.1.1 2,965 7/8/2022
1.1.0 799 6/10/2022
1.0.9 779 4/28/2022
1.0.8 2,770 6/7/2021
1.0.7 700 3/24/2021
1.0.6 536 3/22/2021
1.0.5 575 3/10/2021
1.0.4 910 2/23/2021
1.0.3 509 2/16/2021
1.0.2 597 2/4/2021
1.0.1 539 1/18/2021
1.0.0 807 1/3/2021
1.0.0-preview 591 3/21/2019