smartjni--simpler and more efficient JNI interface encapsulation __android

Source: Internet
Author: User
Tags reflection
The most common scenario we encounter during the Android NDK development process is the use of JNI callback Java APIs. JNI can be understood as a local version of the Java Reflection framework.       The native interface provided by JNI, if you need to get methodid or FieldID through reflection, you need to write out the signature of the Write function and the field (sign), and the call process is extremely cumbersome, detailed instructions, you can refer to the link JNI use tutorial.       In addition, the reflection APIs under the Java layer are much simpler to use and refer to the link Java Reflection Tutorial. The introduction of Smartjni, the main purpose of the two: first, the screen to avoid the Java and JNI two sets of reflection API in the use of the differences; second, the object-oriented approach to encapsulate the native API of JNI, greatly reduce the amount of development code, and more readable.
The main technical points of realizing the principle Smartjni are as follows: First, it is the details of the function signature of the screen avoidance, no need for the caller to write the signature string, detailed implementation, see source Method.cpp.
Second, the transfer between the variable parameters in the local code and the Java layer variable parameters, and the detailed implementation, see source Method.cpp.
Example comparison of native JNI invocation examples is not available, there are many on the web, below is a comparison of examples using the Smartjni and Java APIs:


Smartjni Call Example




JAVA Invocation Example
Through the Smartjni encapsulation, both in use, in addition to its own grammatical limitations, basically has been consistent.
Finally, it is indicated that the SMARTJNI can not complete the alternative jni, but it is basically available. To completely replace the JNI, it will take some time to improve, SMARTJNI project has been open source in Googlecode, address is http://code.google.com/p/smart-jni/, you can checkout through SVN. In addition, if you are interested in with me to improve the SMARTJNI, you can also find me in private, I opened read and write permissions.
PS: If you have any good suggestions, you can directly on the Googlecode on the wiki to give me feedback, thank you.

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.