On Oct 9, 2011, at 11:37 AM, Holy Samosa wrote:
> My basic question is: can I build a native Android app that hosts a Mono
> assembly? What if that assembly needs to make callbacks into the native code?
In theory, yes. I haven't tried this, but I don't see why it wouldn't work.
You'd need to use the Mono Embedding API to initialize mono and load your
assembly:
http://www.mono-project.com/Embedding_Mono
You'd need to dlopen() Mono for Android's libmonodroid.so in Release builds,
then use dlsym() to load the appropriate export from libmonodroid.so at runtime
(rather like LoadLibrary() + GetProcAddress()).
As for the assembly calling into native code, there's P/Invoke (specify the
appropriate library name), and [DllImport("__Internal")] may be relevant, or
you can use delegates/function pointers.
> Thus, I'm considering writing the app in Java and putting the .NET code in a
> library, if this is possible.
An alternate approach (which would be likely far easier to do) would be to
write a "normal" Mono for Android app, including your custom Java code and
packages, and have your Java code call into managed code via the generated
Android Callable Wrappers. There are currently a number of limitations in this
approach (e.g. you can't export arbitrary methods from managed code to Java),
but it may be viable.
http://docs.xamarin.com/android/advanced_topics/architecture
http://docs.xamarin.com/android/advanced_topics/architecture/android_callable_wrappers
http://docs.xamarin.com/android/advanced_topics/build_process#Java_Interop_Support
- Jon
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid