How to create a C # DLL for Xamarin.Android from C ++
I have an iPad app written in C # using Xamarin.IOS that uses some C ++ code that has been built into the C # DLL by following the instructions here .
Now I want to add an Android version of the application, so I need to create a version of this DLL that is compatible.
For the Xamarin.IOS version, the process is essentially:
- C ++ code compiled with Xcode to generate lib.a file
- SWIG is used to generate some C # interface files from C ++ header files.
- Xcode creates a libWrapper.a file from one of the SWIG files it generates
- SMCS (looks like a Xamarin tool command line tool) combines lib.a, libWrapper.a and AssemblyInfo.cs files into C # dlls that can be added as a reference to an iPad project.
Using a DLL already generated in a Xamarin.Android project doesn't work (it throws a P / Invoke EntryPointNotFound error), presumably because it is built for iOS devices (i386, arm7 and arm7s) and needs to be built differently for Android?
I think I need to use the Android NDK to compile C ++ (as opposed to XCode), but what would that create and how do I convert it to a C # DLL to add it to my Xamarin.Android project?
source to share
Android NDK will create a .so file. You can use the same PInvoke methods as in your iOS wrapper. I've used SWIG with Android before, so there shouldn't be any difference since it's a C interface.
Add a .so file to your library project and set it up as EmbeddedNativeLibrary.
http://developer.xamarin.com/guides/android/advanced_topics/using_native_libraries/
source to share