[mono-android] Help with .so and java source
jonp at xamarin.com
Tue Feb 21 18:21:04 UTC 2012
On Feb 20, 2012, at 4:54 AM, Goncalo Oliveira wrote:
> I'm kind of out-of-date with this, maybe someone can give he a hand...
> I'm "translating" the c header into c# in order to import the methods from the .so library. The this is that mangled names make this a bit messy to maintain; for example:
> int Msg_IsConnected() => mangled name => Java_com_alk_sdk_AlkMsg_Msg_1IsConnected
The question is one of intent and semantics.
If the native library provider is providing a "real" C library, then I would expect them to have "normal" C exports, specifically something _without_ a Java_ prefix.
If the only useful methods are those provided for Java/JNI (e.g. JNI_OnLoad, Java_com_alk_sdk_AlkMsg_Msg_1IsConnected), then the native library is probably _not_ intended for "normal" C use, but is instead intended for use from Java, in which case you should use Java/JNI to interact with the native library and not P/Invoke.
The reason for this is that you don't know what the native library does, nor can you properly provide the parameters. For example, Java_com_alk_sdk_AlkMsg_Msg_1IsConnected should start with either a `(JNIEnv *env, jclass klass` or `(JNIEnv *env, jobject this` parameter pair: how are you going to provide the JNIEnv*, jclass, or jobject values? You're not. :-)
In short, don't P/Invoke any Java_* or JNI_* methods. That way leads to madness.
I would suggest that you see if they have an actual documented C interface, and stick to that, ignoring other exports that objdump shows you.
More information about the Monodroid