一 关于JNI的介绍
https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html
目录中红色字体标注的章节为必看章节:
下面是目录:
Java Native Interface Overview
Background
JDK 1.0 Native Method Interface
Java Runtime Interface
Raw Native Interface and Java/COM Interface
Objectives
Java Native Interface Approach
Programming to the JNI
Changes in JDK 1.1.2
JNI Interface Functions and Pointers
Compiling, Loading and Linking Native Methods
Resolving Native Method Names
Native Method Arguments
Global and Local References
Implementing Local References
Accessing Primitive Arrays
Accessing Fields and Methods
Reporting Programming Errors
Java Exceptions
Exceptions and Error Codes
Asynchronous Exceptions
Exception Handling
3. JNI Types and Data Structures
Primitive Types
Reference Types
Field and Method IDs
The Value Type
Type Signatures
Modified UTF-8 Strings
Interface Function Table
Version Information
DefineClass
FindClass
GetSuperclass
IsAssignableFrom
Throw
ThrowNew
ExceptionOccurred
ExceptionDescribe
ExceptionClear
FatalError
ExceptionCheck
NewGlobalRef
DeleteGlobalRef
DeleteLocalRef
EnsureLocalCapacity
PushLocalFrame
PopLocalFrame
NewLocalRef
NewWeakGlobalRef
DeleteWeakGlobalRef
AllocObject
NewObject, NewObjectA, and NewObjectV
GetObjectClass
GetObjectRefType
IsInstanceOf
IsSameObject
GetFieldID
Get<type>Field Routines
Set<type>Field Routines
GetMethodID
Call<type>Method Routines, Call<type>MethodA Routines, and Call<type>MethodV Routines
CallNonvirtual<type>Method Routines, CallNonvirtual<type>MethodA Routines, and CallNonvirtual<type>MethodV Routines
GetStaticFieldID
GetStatic<type>Field Routines
SetStatic<type>Field Routines
GetStaticMethodID
CallStatic<type>Method Routines, CallStatic<type>MethodA Routines, and CallStatic<type>MethodV Routines
NewString
GetStringLength
GetStringChars
ReleaseStringChars
NewStringUTF
GetStringUTFLength
GetStringUTFChars
ReleaseStringUTFChars
GetStringRegion
GetStringUTFRegion
GetStringCritical
Release StringCritical
GetArrayLength
NewObjectArray
GetObjectArrayElement
SetObjectArrayElement
New<PrimitiveType>Array Routines
New<PrimitiveType>Array Routines
ArrayType New<PrimitiveType>Array(JNIEnv *env, jsize length);
实际上调用方法为:env->
New<PrimitiveType>Array(jsize length).
NativeType *
Get<PrimitiveType>ArrayElements(JNIEnv *env,
ArrayType
array, jboolean *isCopy);
A family of functions that returns the body of the primitive array. 在C/C++代码中,从原始数组类型中获取数据元素。
A family of functions that informs the VM that the native code no longer needs access to elems
. The elems
argument is a pointer derived from array
using the corresponding Get<
PrimitiveType>
ArrayElements() function. If necessary, this function copies back all changes made to elems
to the original array.
The mode
argument provides information on how the array buffer should be released. mode
has no effect if elems
is not a copy of the elements in array
. Otherwise, mode
has the following impact, as shown in the following table:
Table 4-10 Primitive Array Release Modes
mode | actions |
---|---|
| copy back the content and free the |
| copy back the content but do not free the |
| free the buffer without copying back the possible changes |
Get<PrimitiveType>ArrayRegion Routines
Set<PrimitiveType>ArrayRegion Routines
GetPrimitiveArrayCritical
ReleasePrimitiveArrayCritical
RegisterNatives
UnregisterNatives
NewDirectByteBuffer
GetDirectBufferAddress
GetDirectBufferCapacity
FromReflectedMethod
FromReflectedField
ToReflectedMethod
ToReflectedField
Creating the VM
Attaching to the VM
Unloading the VM
Library and Version Management
JNI_GetDefaultJavaVMInitArgs
JNI_GetCreatedJavaVMs
JNI_CreateJavaVM
DestroyJavaVM
AttachCurrentThread
AttachCurrentThreadAsDaemon
DetachCurrentThread
GetEnv
二、网络上的一些资料
1、https://blog.youkuaiyun.com/lzpdz/article/details/51544134
Android JNI 使用的数据结构JNINativeMethod详解
2、https://blog.youkuaiyun.com/cubesky/article/details/38754045
registerNativeMethods 介绍
3、https://developer.android.google.cn/studio/projects/add-native-code.html?hl=zh-cn