Android applications may require ndk implementation due to performance issues. For multimedia applications such as OpenGL and opencore, local
The C/C ++ language can handle some performance-sensitive or complex algorithms. android123 summarizes the problems and skills encountered in our daily ndk development for users to check.
1. android ndk-compiled applications can run on Android 1.5 or later operating systems. Local calls on Android platforms are mainly handled through JNI, the JNI call overhead is not small. If it is very simple, there is no need to draw a picture.
2. How to package the so file generated by ndk into the APK? Create a libs folder under the project directory, and manually release the folder, for example, data/cn.com. android123.cwj/files/Rmvb-decoder.so
3. In JNI, we often use the following naming methods:
Static JavaVM * g_vm; // Global Environment pointer
Static jclass jnativesclass;
(* Env)-> getjavavm (ENV, & g_vm); // obtain the ENV Environment pointer, so you can use g_vm later.
4. jobjectarray jargv // Java Array
Int getarraylen (jnienv * ENV, jobjectarray jarray): // gets the length of a Java array and returns the jsize type.
Jstring jele = (jstring) (* env)-> getobjectarrayelement (ENV, jargv, n); // convert the Java array element N to a local jstring
Const char * word = (* env)-> getstringutfchars (ENV, jele, 0); // convert the Java UTF character into the char * in C *
5. Remember to release the memory, which is not Java
(* Env)-> releasestringutfchars (ENV, jele, word );
6. Java class naming
(Ljava/lang/string; I) v.
I = integer
B = byte
S = short
C = char
Lxxx; = l add the class name
7. JNI itself has no technical content. android123 reminds everyone that users who use C language only need to know how to transmit data through JNI in Java and C/C ++.
8. How does JNI and Java transmit large data? In fact, some flexible methods can be used to process large data by sharing a file.