NDK方法名的设计:必须按照JNI的接口规范来设计方法名,参考官方文档:
### Resolving Native Method Names
Dynamic linkers resolve entries based on their names. A native method name is concatenated from the following components:
* the prefix `Java_`
* a mangled fully-qualified class name
* an underscore (“_”) separator
* a mangled method name
* for overloaded native methods, two underscores (“__”) followed by the mangled argument signature
The VM checks for a method name match for methods that reside in the native library. The VM looks first for the short name; that is, the name without the argument signature. It then looks for the long name, which is the name with the argument signature. Programmers need to use the long name only when a native method is overloaded with another native method. However, this is not a problem if the native method has the same name as a nonnative method. A nonnative method (a Java method) does not reside in the native library.
In the following example, the native method `g` does not have to be linked using the long name because the other method `g` is not a native method, and thus is not in the native library.
class Cls1 {
int g(int i);
native int g(double d);
}
简而言之,正常的设计方法是Java_+被调用处的完整类名_+函数方法名:
如在com.example.jni下面有个Cls1调用了NDK的g方法,那么这个NDK方法需要被命名成:
Java_com_example_jni_Cls1_g即可