Android JNI and androidjni
Android JNI topics are divided into four phases:
- Jni simple demo
- Introduction to basic Jni data types and Methods
- Jni parses java Custom Data Types and callback java Methods
- Jni performance Improvement and Exception avoidance
The CHM and PDF documents have been compiled. You are welcome to download them. refer:
CHM: http://download.csdn.net/detail/cofftech/7657291
PDF: http://download.csdn.net/detail/cofftech/7657309
Android jni Problems
1. on Android, whether Java or C/C ++ is used depends on your actual situation. If you are porting the existing C/C ++ program, it is undoubtedly NDK, or when you focus on program memory control and execution efficiency, you have to take the native route. After all, the Java features will lead to a slight difference in these aspects. If it is not the case above, it is good to directly use the Java-layer HttpConnection and so on. After all, it is easy to use. The issue of Native debugging for Android is indeed a headache in the 1.6 era. But with the continuous development of NDK and the official attention to this issue, now 2. the version of X (as if it was 2.2, you can check it on the official website) already supports GDB Command Line Debugging. Of course, this is not as silly as VS debugging, breakpoint, to skip the step, you must be familiar with the GDB command, but it can indeed be debugged.
2. this problem has nothing to do with the Android system. If you use socket to implement TCP connection, you can define the structure of the data packet, for example, send Buffer: 4 bytes (int mark command number) + 2 bytes (short command parameter) + 1 byte (char command parameter) structure, or you can refer to the encapsulation mode structure such as FTP and HTTP, of course, this must also work with your server logic. If your server is a Web server, it will be over HTTP.
Personal opinion, for reference only.
What is the difference between Android JNI and NDK?
JNI is the abbreviation of Java Native Interface. Java Native Interface (JNI) standards have become part of the java platform since Java1.1. It allows Java code to interact with code written in other languages. JNI was initially designed for locally compiled languages, especially C and C ++, but it does not prevent you from using other languages, as long as the call conventions are supported. Using java to interact with locally compiled code usually results in loss of platform portability. However, in some cases, this is acceptable or even necessary. For example, you can use old libraries to interact with hardware and operating systems, or to improve program performance. The JNI standard should at least ensure that local code can work under any Java Virtual Machine implementation. Standard java class libraries may not support the features required by your program. JNI-you may already have a library or program written in other languages, and you want to use it in java programs. You may need to use the underlying language to implement a small time-sensitive code, such as assembly, and then call these functions in your java program. NDK is an Application Development Kit launched by Google to help Android Developers compile applications in C/C ++ local languages, contains C/C ++ header files, library files, instructions and sample code. We can understand that, like Windows Platform SDK, it is written in pure C/C ++, however, Android does not support applications written in pure C/C ++. At the same time, the library and function functions provided by NDK are very limited. It only handles some algorithm efficiency-sensitive issues, therefore, it is recommended that beginners learn Java before learning JNI. NDK integrates with the cross compiler and provides mk files to isolate differences such as CPU, platform, and ABI, developers can create so simply by modifying the mk file (indicating "which files need to be compiled" and "Compilation feature requirements. NDK can automatically package so and Java applications, greatly reducing developers' packaging work.