Using Native Libraries
Let us know how you feel about this.
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:
- Path "sniffing"
- Using a
//AndroidNativeLibrary/Abielement 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
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.
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.