[I'm really sorry if this message shows up multiple times.  I'm having problems 
changing my email address with Nabble & ths list, so there are a couple of 
copies awaiting moderation...  Grrr]

Thanks for the knowledge drop, guys.

So, if I elected to just build a 'normal' Mono for Android app and wanted to 
leverage a third-party graphing component such as aiCharts, I'd need to roll my 
own interop with JNI as documented here: 
http://docs.xamarin.com/android/advanced_topics/api_design#Java_Native_Interface_Support

And additionally, I'm assuming I wouldn't be able to use the charting component 
in .AXML files, but rather would have to instantiate programically.

Am I anywhere near correct here?

Thanks!
Jeremy

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Jonathan Pryor
Sent: Monday, October 10, 2011 1:52 PM
To: Discussions related to Mono for Android
Subject: Re: [mono-android] Hosting Mono code from native code?

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
_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to