Native Library Interop for .NET MAUI

repository·main·Indexed 42 days ago

https://github.com/communitytoolkit/maui.nativelibraryinterop

A 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.

Tokens
1.4K
Snippets
4
Records
12
Agent score
54%

What's inside Native Library Interop

  1. What is Native Library Interop?

    main
    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.
  2. Consume existing bindings (Facebook, Firebase, Google Cast)

    main

    This repository contains sample bindings and MAUI apps for Facebook, Firebase (Analytics and Messaging), and Google Cast. To use them in your own project:

    1. Clone or submodule this repository.
    2. Navigate to the specific binding directory (e.g., firebase/macios/Firebase.MaciOS.Binding for Firebase Messaging) and read its local README for specific build and configuration instructions.
    3. Reference the binding project in your .NET MAUI .csproj file, or build the binding projects and reference the resulting .dll assembly 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" />
  3. Deploy the Firebase sample to a physical iOS device

    main

    To deploy the sample to a physical device, you must handle code signing and APNs configuration in Xcode:

    1. Open Project: Open macios/native/MauiFirebase.xcodeproj in Xcode.
    2. Configure Signing: Navigate to Targets -> MauiFirebase -> Signing & Capabilities and configure your signing team and settings.
    3. Configure APNs: Ensure you have a provisioning profile installed that supports Apple Notification Service (APNs) to enable messaging features.
  4. Configure Facebook App identifiers for Android

    main

    To make the Android sample functional, you must update the strings.xml file with your Facebook developer credentials.

    Path: facebook/sample/Platforms/Android/Resources/values/strings.xml

    Required updates:

    1. Replace YOUR_APP_ID with your Facebook App ID.
    2. Replace YOUR_CLIENT_TOKEN with your Facebook App Client Token.
  5. Get started with a new binding using the template

    main

    To 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.
  6. Configure Firebase for the iOS sample

    main

    The Firebase Slim Binding sample requires a valid Firebase configuration to function. Follow these steps to set up your Firebase iOS app:

    1. Download Configuration: Download your GoogleService-Info.plist from the Firebase console.
    2. Replace File: Replace the existing sample/Platforms/iOS/GoogleService-Info.plist with your downloaded file.
    3. Update Application ID: Open Sample.csproj and update the <ApplicationId> value to match your Firebase iOS app identifier.