Some problems with Monodroid calling JNI Native

Source: Internet
Author: User

In the process of Android version development, we need to use some of the NDK's native libraries developed with JNI. Here to talk about stepping on the pit, for everyone's reference.

Although Java program I am familiar with, but did not understand the development of JNI Native, is generally directly developed. NET call. So library. There is a library from Java code porting, and there is no source code, and then encountered some problems. First, the name of the function of the JNI is required,. NET can directly invoke native-looking libraries such as the monodroid example[DllImport ("Sanangeles", EntryPoint = "Java_com_example_sanangeles_demorenderer_nativeinit")] private static extern void Nativeinit (IntPtr jnienv);       Java requires naming according to Java_pakcage_class_method. Look at the Java declarationclass Demorenderer implements Glsurfaceview.renderer {Public void onsurfacecreated (GL10 gl, EGLConfig config) {nativeinit ();                 }private static native void Nativeinit ();If you do not have the JNI source code, do not know the function declaration, you write this[DllImport ("Sanangeles",entrypoint = "Nativeinit")] private static extern void Nativeinit (IntPtr jnienv); Then wait to play, if you improve the Java source code, be sure to pay attention to the EntryPoint statement. Second, can not find the library, instruction set (eabi,eabi-v7a) of the problem by default debugging, Xamarin debugging state, according to the Android environment, the execution of the selected instruction set. The problem comes, it can't make you choose.       Then your libs only Eabi. So, there will be problems that the DLL cannot find. Debug State, add the target library of eabi-v7a.        Or when using a virtual machine, select the Armeabi environment. You can see whether the library is copied to the/data/app/package/lib directory through the ADB shell and into the system.       Third, JNI returns the processing of a string. Many of the methods introduced by Monodroid are called by JNIEnv class reflection, and it is not necessary to use the Reflection method var ver =XXX(JNIEnv. Handle);var s = new Java.Lang.Object (ver, jnihandleownership.transferglobalref). Javacast<java.lang.string> ().               ToString (); Ver is IntPtr, so avoid using reflection and make a few more conversions. Recommendation: If a library of functions written using the NDK is only invoked with monodroid, there is no need to use the JNI specification, which is more efficient and does not require an incoming JNIEnv object.

Some problems with Monodroid calling JNI Native

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.