.NET MAUI
Native Interop & Libraries
7 question(s)
How do you add a NuGet package to a MAUI project?
Beginner
Add it like any .NET package (dotnet add package or the IDE), ensuring the package supports the MAUI target frameworks. Cross-platform packages 'just work'; platform-specific ones may only apply to certain TFMs. Check for MAUI compatibility before adopting a library.
dotnet add package CommunityToolkit.Maui
Real-world example
A team adds CommunityToolkit.Maui and initializes it with UseMauiCommunityToolkit() to gain popups and behaviors.
Common follow-ups: How do you know a package supports MAUI? | Do all packages target every platform?
NuGet
Dependencies
Native Interop & Libraries
How do you call a native Android library (Java/Kotlin) from MAUI?
Intermediate
Use a .NET for Android binding library that projects the Java/Kotlin AAR or JAR into C# through a bindings project, then reference it from Platforms/Android code. Microsoft provides binding tooling and metadata transforms to fix API surface issues.
// In an Android bindings project, reference the .aar,
// then call the generated C# API from Platforms/Android.
var client = new Com.Vendor.Sdk.Client(context);
Real-world example
A payment SDK shipped only as an Android AAR is consumed by generating a C# binding and calling it from Android-specific code.
Common follow-ups: What is a bindings project? | How do you fix a broken generated API?
Android
Platform Integration
Native Interop & Libraries
How do you call native iOS (Objective-C/Swift) libraries from MAUI?
Intermediate
Use a .NET for iOS binding library with ApiDefinition and Structs files describing the native framework, then reference it from Platforms/iOS. Objective-C binds directly; Swift usually needs an Objective-C-compatible interface. Objective Sharpie can generate a starting binding.
var analytics = new Vendor.Analytics();
analytics.TrackEvent("purchase");
Real-world example
An iOS-only analytics framework is bound with Objective Sharpie and invoked from iOS platform code.
Common follow-ups: What is Objective Sharpie? | Why do Swift libraries need extra work?
iOS
Platform Integration
Native Interop & Libraries
How do you evaluate whether a third-party library is production-ready for MAUI?
Advanced
Check that it targets current MAUI TFMs, is actively maintained, supports all your platforms, is trim/AOT-safe, has a compatible license, and does not bloat the app. Prefer well-known packages (CommunityToolkit) and vet native bindings for update cadence, since abandoned bindings become migration liabilities.
Real-world example
A team rejects an unmaintained charting binding in favor of a trim-safe, actively developed alternative to avoid future breakage.
Common follow-ups: Why does trim-safety matter? | What risks come with native bindings?
Dependencies
Trimming
Native Interop & Libraries
How do you share code between a MAUI app and other .NET projects (web/API)?
Intermediate
Put shared models, DTOs, validation, and business logic in a plain .NET class library referenced by both the MAUI app and the server. Keep platform and UI concerns out of it. This maximizes reuse and keeps a single source of truth for contracts.
// Shared.csproj referenced by MyApp.Maui and MyApp.Api
public record ProductDto(int Id, string Name, decimal Price);
Real-world example
The same DTOs and validation rules compile into both the API and the MAUI client, preventing contract drift.
Common follow-ups: What belongs in the shared library? | Why keep UI out of it?
Architecture
Dependency Injection
Native Interop & Libraries
How do you expose native SDK features cleanly through dependency injection?
Advanced
Define a shared interface for the capability, implement it per platform (calling the bound native SDK) under Platforms/, and register it in DI. Consumers depend only on the interface, which isolates the binding, allows mocking in tests, and lets you swap SDKs without touching app logic.
public interface IAnalytics { void Track(string evt); }
// Platforms/Android + Platforms/iOS implement via native SDKs
builder.Services.AddSingleton<IAnalytics, Analytics>();
Real-world example
Firebase Analytics (native on each platform) sits behind one IAnalytics so view models call a single Track method.
Common follow-ups: Why hide the SDK behind an interface? | How does this aid testing?
Dependency Injection
Platform Integration
Native Interop & Libraries
How do you conditionally reference a package only for specific platforms?
Advanced
Use an MSBuild condition on the PackageReference keyed off the TargetFramework moniker, so a platform-only dependency is restored just for that head. This avoids pulling Android-only or iOS-only libraries into targets that cannot use them.
<ItemGroup Condition="$(TargetFramework.Contains('-android'))">
<PackageReference Include="Xamarin.AndroidX.Biometric" Version="1.1.0.19" />
</ItemGroup>
Real-world example
An Android biometric package is referenced only for the net-android target, keeping the iOS and Windows builds lean.
Common follow-ups: How does the condition key off the TFM? | Why not reference it everywhere?
Multi-targeting
Dependencies
Native Interop & Libraries