Using Native Libraries

PDF for offline use:

Xamarin.Android supports the use of native libraries via the standard PInvoke mechanism. You can also bundle additional native libraries which are not part of the OS into your .apk.

To deploy a native library with a Xamarin.Android application, add the library binary to the project and set its Build Action to AndroidNativeLibrary.

To deploy a native library with a Xamarin.Android library project, add the library binary to the project and set its Build Action to EmbeddedNativeLibrary.

Note that since Android supports multiple Application Binary Interfaces (ABIs), Xamarin.Android must know which ABI the native library is built for. There are two ways this can be done:

  1. Path "sniffing"
  2. Using a //AndroidNativeLibrary/Abi element within the project file

With path sniffing, the parent directory name of the native library is used to specify the ABI that the library targets. Thus, if you add lib/armeabi/libfoo.so to the project, then the ABI will be "sniffed" as armeabi.

Alternatively, you can edit your project file to explicitly specify the ABI to use:

<ItemGroup>
    <AndroidNativeLibrary Include="path/to/libfoo.so">
        <Abi>armeabi</Abi>
    </AndroidNativeLibrary>
</ItemGroup>

For more information about using native libraries, see Interop with native Libraries.