开发者

JNI - How to create a library for different classes

I'm new to JNI, i'm deve开发者_运维技巧loping a native library for an Android project. I read some papers about JNI programming but i didn't understand if it is possible to create a library that can be loaded in different project classes with different packages. I read that to declare a new JNI method the syntax is:

  • the prefix "Java_"
  • an encoded fully qualified class name
  • an underscore ("_") separator
  • an encoded method name

Based on this definition it shouldn't be possible...

Suppose i had defined a class A in the package pkg1 with the native method foo contained in libfoo, and then i defined a class B in the package pkg2. Can i use libfoo and the foo method in B? How should i define the native method to achieve the result?

Thanks!


On Android, the recommended way to register natives is to use JNI's RegisterNatives(), because it's faster than the Java_* lookup mechanism.

And doing so, you should be able to register the same native method into several classes/packages if you like.


Check out the JNI header stub generator: http://download.oracle.com/docs/cd/E17476_01/javase/1.5.0/docs/tooldocs/windows/javah.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜