Using Native Libraries

PDF for offline use
Sample Code:

Let us know how you feel about this

Translation Quality


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/ 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:

    <AndroidNativeLibrary Include="path/to/">

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

Debugging Native Code with Visual Studio 2015

If you're using Visual Studio 2015, you don't have to modify your project files (as described above). You can build and debug C++ inside your Xamarin.Android solution, simply by adding a project reference to a C++ Dynamic Shared Library (Android) project.

Visual Studio C++ developers can see the SanAngeles_NativeDebug sample to try debugging C++ from Visual Studio 2015 with Xamarin; and refer to our blog post for more information.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.