Native Library Bindings
Question
Is it possible to use Java library in Xamarin.Android and Objective-C/Swift libraries in Xamarin.iOS?
Short interview answer
Yes, but through bindings or interoperable APIs rather than by directly treating Java, Objective-C, or Swift source as C#. A binding exposes the native library’s supported API to managed code and introduces versioning, ownership, and platform-toolchain constraints.
Detailed answer
For Xamarin.Android, a binding library can wrap a Java or Kotlin library so C# calls cross the Java Native Interface boundary. The binding must include compatible Java and native dependencies, and its target API level must be compatible with the library. On iOS, use a supported .NET iOS binding or write one for an Objective-C-compatible API; Swift libraries often need an Objective-C-compatible surface before binding. Treat the binding as an integration boundary: validate initialization, threading, callbacks, memory ownership, and updates against the actual devices.
Glossary
- API: Application programming interface.
- JNI: Java Native Interface.