Native Library Interop for .NET MAUI
repository·main·Indexed 42 days ago
https://github.com/communitytoolkit/maui.nativelibraryinteropA toolkit providing patterns, templates, and samples for accessing native SDKs on Android, iOS, and Mac Catalyst from .NET MAUI applications using the Native Library Interop (formerly Slim Bindings) pattern. Includes sample bindings and configuration guides for Facebook, Firebase, and Google Cast.
What's inside Native Library Interop
- Native Library Interop (formerly known as "Slim Bindings") is a pattern used to access native SDKs within .NET MAUI applications. It supports .NET for Android, .NET for iOS, and .NET for Mac Catalyst. This project provides templates and samples to help developers create new bindings or consume existing ones constructed via this interop pattern.
Build and run the Firebase Slim Binding sample
mainTo build and run the Firebase Slim Binding sample for iOS using the .NET CLI, use the following command. This sample demonstrates basic usage of Firebase Analytics, Auth, and Messaging.
dotnet build sample -t:Run -f net9.0-iosConsume existing bindings (Facebook, Firebase, Google Cast)
mainThis repository contains sample bindings and MAUI apps for Facebook, Firebase (Analytics and Messaging), and Google Cast. To use them in your own project:
- Clone or submodule this repository.
- Navigate to the specific binding directory (e.g.,
firebase/macios/Firebase.MaciOS.Bindingfor Firebase Messaging) and read its localREADMEfor specific build and configuration instructions. - Reference the binding project in your .NET MAUI
.csprojfile, or build the binding projects and reference the resulting.dllassembly artifacts.
Note: There are currently no plans to ship these bindings via NuGet packages.
<!-- Example: Adding a project reference for Firebase Messaging in your .csproj --> <ProjectReference Include="<YourPathToClonedRepo>\firebase\macios\Firebase.MaciOS.Binding\Firebase.MaciOS.Binding.csproj" />Configure Facebook App identifiers for iOS
mainTo make the iOS sample functional, you must update the
Info.plistfile with your Facebook developer credentials.Path:
facebook/sample/Platforms/iOS/Info.plistRequired updates:
- Replace
YOUR_APP_IDwith your Facebook App ID. - Replace
YOUR_CLIENT_TOKENwith your Facebook App Client Token.
- Replace
Configure signing for Google Cast on physical iOS devices
mainTo deploy the Google Cast sample to a physical iOS device, you must configure code signing in Xcode:
- Open
macios/native/MauiGoogleCast.xcodeprojin Xcode. - Navigate to Targets -> MauiGoogleCast -> Signing & Capabilities.
- Configure your development team and signing settings.
- Open
Deploy the Firebase sample to a physical iOS device
mainTo deploy the sample to a physical device, you must handle code signing and APNs configuration in Xcode:
- Open Project: Open
macios/native/MauiFirebase.xcodeprojin Xcode. - Configure Signing: Navigate to
Targets->MauiFirebase->Signing & Capabilitiesand configure your signing team and settings. - Configure APNs: Ensure you have a provisioning profile installed that supports Apple Notification Service (APNs) to enable messaging features.
- Open Project: Open
Configure Facebook App identifiers for Android
mainTo make the Android sample functional, you must update the
strings.xmlfile with your Facebook developer credentials.Path:
facebook/sample/Platforms/Android/Resources/values/strings.xmlRequired updates:
- Replace
YOUR_APP_IDwith your Facebook App ID. - Replace
YOUR_CLIENT_TOKENwith your Facebook App Client Token.
- Replace
Get started with a new binding using the template
mainTo create a new native library binding, copy the contents of this template repository and follow the official Microsoft documentation.
The template is structured to separate the .NET binding logic from the native source code for multiple platforms. Use this structure to organize your project:
- Android:
NewBinding.Android.Binding: The .NET API project that wraps the native code.native: The Android project containing the Java or Kotlin code.
- macOS/iOS:
NewBinding.MaciOS.Binding: The .NET API project that wraps the native code.native: The Xcode project containing the Objective-C code.
- Sample App:
sample: A .NET MAUI application demonstrating how to consume the newly created binding.
- Android:
Build and run the Google Cast Slim Binding sample
mainTo build and execute the Google Cast Slim Binding sample project, use the
dotnet buildcommand with theRuntarget on thesampledirectory.dotnet build sample -t:RunConfigure Firebase for the iOS sample
mainThe Firebase Slim Binding sample requires a valid Firebase configuration to function. Follow these steps to set up your Firebase iOS app:
- Download Configuration: Download your
GoogleService-Info.plistfrom the Firebase console. - Replace File: Replace the existing
sample/Platforms/iOS/GoogleService-Info.plistwith your downloaded file. - Update Application ID: Open
Sample.csprojand update the<ApplicationId>value to match your Firebase iOS app identifier.
- Download Configuration: Download your
Build and run the Facebook Slim Binding sample
mainTo build and run the Facebook Slim Binding sample application for Android or iOS, use the
dotnet buildcommand with theRuntarget and specify the appropriate target framework.dotnet build sample -t:Run -f net9.0-android dotnet build sample -t:Run -f net9.0-iosCreate a new native binding
mainTo create your own binding using the Native Library Interop pattern:
- Copy the contents of the
templatedirectory in this repository to your project. - Follow the detailed getting started instructions provided in the official Microsoft Learn documentation.
- Copy the contents of the