How to Use JNI: How to Use JNI
1. in java, public native void + method name ("");2. Then load the required underlying so file system. loadLibrary ("so file name cannot be suffixed ")3. When you need to call the native method, you can call it as a normal method.The following is the implementation of the underlying C or C ++1. Find the directory where your project is located and open cmd to enter the directo
for JavaProgrammers,Javathe advantages and advantages of the language, I do not want to say, we will naturally say a lot of condoms. But while we asJavaprogrammer, but we have to admitJavaThe language also has some drawbacks of its own. For example, the performance, and the bottom of the deal with its shortcomings. SoJavaprovides a number of local interfaces, his primary role is to provide a standard way forJavaThe program interacts with the native co
hard for me to stubbornly think. The makefile syntax is simple, so you can just knock on one. But looking back at ant's build. XML, it looks dizzy at first glance.XML is very good, but it's just a mess of his uncle, and he claims to say that it's something for people to see... Everything really has some substantial use, and the data stored in XML (used to demonstrate XML like Hello world is free of use) makes people look dizzy.
Ant uses XML as the basic input. I personally think it is better to
This section learns to use the C language to encrypt strings, and everyone knows that encryption using Java implementations can be deserialized, whereas encryption using C writes is hard to decompile. So we use JNI to learn how to use C to implement the encryption of strings.First: We implement an interfaceThe layout file is subsidized.Second: Add a local method of encryption and decryption to the mainactivityEncrypt local method public native string
Copyright notice: This article from Administration Blog, reproduced please indicate the source: http://blog.csdn.net/a_zhon/.Directory (?) [+]One: What is JNI?
JNI:JNI is the abbreviation for Java Native Interface , which provides a number of APIs that enable the communication of Java and other languages (mainly cc++), in simple terms Java tuning c,c java.
Second: start to build our development environment, is also very simpledev-c++ too
This section learns to use the C language to encrypt strings, and everyone knows that encryption using Java implementations can be deserialized, whereas encryption using C writes is very difficult to decompile. So we use JNI to learn how to use C to implement the encryption of strings.First: We implement an interfaceThe layout file is subsidized.Second: Add a local method of encryption and decryption to the mainactivityEncrypt local method public nati
jstringLjava/net/socket; Socket JobjectIf the JAVA function is in an embedded class (also known as an inner class), use $ as the delimiter between the class names, for example: "Landroid/os/fileutils$filestatus;".Finally, the 64th line of code is used to register all the JNI local methods recorded in the Jninativemethod structure.Using the Registernativemethods method is not just to change the ugly long me
local method. This Pointer Points to the internal data structure in the JVM, and the internal data structure is invisible in the memory. The local code must select an appropriate JNI function in jnienv to operate on objects in the JVM.
The jnienv interface pointer of the first parameter points to a function table, and each entry in the function table points to a JNI function. Local methods often use these
relationship// Obtain the method length www.2cto.comMethodsLenght = sizeof (methods)/sizeof (methods [0]);If (* env)-> RegisterNatives (env, clazz, methods, methodsLenght) LOGE ("RegisterNatives failed for '% S'", className );Return JNI_ERR;}//Result = JNI_VERSION_1_4;Return result;}The key to establishing the ing between the c/c ++ method and the Java method is the JNINativeMethod structure, which is defined in jni. h. The specific definitions are a
small "cpufeatures" static library, which can be used to obtain the features currently supported by the CPU during JNI running. This library supports all platforms starting from Android 1.5. For more detailed information about the database, see cpu-features.txt.
(6) support the optional arm advanced SIMD (a.k. A. Neon) features. The following CPU-related features are still well studied by friends interested in hardware optimization. Note that there i
); register_android_server_systemserver (env); register_android_server_location_gpslocationprovider (env); register_android_server_connectivity_vpn (env); register_android_server_helloservice (env); JNI method Registration return jni_version_1_4; } The onload.cpp file is partially a declaration of a registered function, and the lower part is called a variety of registration functions, which are the registration functions of the
I recently contacted the Android platform JNI call and found that the network information has not provided a more detailed introduction from the principle to the specific implementation. Therefore, I have referenced some materials and added some experiences based on the project development:
Origin of JNIJNI is the abbreviation of Java Native Interface. It allows Java code to interact with code written in other languages.
the Bin/classes directory, you can see the signature of all methods of the class using the JAVAP command.Tip: TheC + + code is ultimately executed in the system process, not in the virtual machine .ExampleExample one: Example of cocos2d-x implementation:The native method declaration in Java is as follows:public static native void logout ();The logout method for calling Java in C + +: #if (Cc_target_platform = = cc_platform_android) #include "jni.
JNI from itwiki
More JNI information can be found in the spec of JNI: http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/jniTOC.htmlJump to: navigation, lt; jumptosearch gt;
JNI is short for Java Native Interface. Since Java 1.1, the Java Native Interface (
embedding a JVM implementation into a local application to execute modules written in Java. for example, a browser written in C ++ uses the embedded JVM to execute the download to a local applet.
The general steps for implementing "JNI-Java invoke native library" are as follows:
1) Complete Java code and write Java call classes
2) compile your Java class
3) Use javah to generate the header file of the C/C
%java_home%/include/win32-ld Helloworldimp.c-fehello.dll
Note: The generated DLL filename is configured after the option-fe, which is Hello, because the name we loadlibary in the Helloworld.java file is hello. Of course, there are changes to be done here. Additional-i%java_home%/include-i%java_home%/include/win32 parameters need to be added because the jni.h file was introduced when the local method was written in step fourth.
6) Running the programJava HelloWorld is OK.
Summary Use examples of
Android JNI development under Eclipse, androidjni
1. Create an Android Project
First, create an Android project named AndroidJniTest. The package name defaults to com. example. androidjnitest. MainActivity. java is automatically created under the src directory.
2. design the JNI Interface
Create a new file package com. examp
I have just been familiar with Android and Java platforms, but I still don't know much about JNI. So I have reposted an article from csdn so that I can understand JNI, I would also like to share with you.
JNIYesJava Native Interface. Since Java 1.1, the Java Native Interface (JNI) standard has become part of the Java platform. It allows Java code to interact with
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.