How to import .dll to Android java project (working with eclipse)

前端 未结 4 1128
醉话见心
醉话见心 2020-12-30 16:33

Java Native Interface (JNI)

Java Native Interface (JNI) is one of the intersting interface by java By using Java Native I

4条回答
  •  悲&欢浪女
    2020-12-30 17:08

    First a disclaimer - I'm a bit sketchy on this, it's been a while since I've used JNI.

    Many JNI examples assume you own the code for the library you want to call, which in my experience is rarely the case. In the example you sight the javah util has been used to generate a header file, against which cpp implementation has been written - this is why you can see the jni header file and various Java keywords in the cpp file.

    In order to use a 3rd party dll, you first need the documentation for that dll, without that you're dead in the water. The reason you need the documentation is that you're going to provide a wrapper dll that simply delegates to the 3rd party dll - you need to know how to call it and how to perform any type mappings. Obviously it's this wrapper that will contain all the JNI stuff to allow Java to make the call to that wrapper, which in turn calls the 3rd party dll.

    There's various ways to do this but the easiest way I know is to use SWIG, which will generate all the C++ code required for the wrapper dll. It also helps to have someone that knows C++ on hand - they'll be invaluable writing interface files (.i or .swg files) that SWIG uses to generate the wrapper code.

提交回复
热议问题