[英]Call C++ library from Java in Android
Is it possible to call a C++ library from an Android app? 是否可以从Android应用程序调用C ++库? If yes, how?
如果有,怎么样?
I have zero experience in Android programming (some Java programming experience though) but I would still like to know if this is possible. 我没有Android编程经验(虽然有些Java编程经验),但我仍然想知道这是否可行。 Given the number of great C++ libraries out there, I would be surprised if it were not possible to call a C++ library from an Android app.
鉴于那里有很多优秀的C ++库,如果无法从Android应用程序调用C ++库,我会感到惊讶。
You need to write an Java Native Interface(JNI) to be able to call the native(c/c++) libraries from Android Java code. 您需要编写Java本机接口(JNI)才能从Android Java代码调用本机(c / c ++)库。
The hierarchy is like: 层次结构如下:
+++++++++++++++++++++++++++++++++++
| Android Application |
+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
| Android Application Framework |
+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
| Java Native Interface |
+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
| C/C++ Native Libraries |
+++++++++++++++++++++++++++++++++++
Yes, it's possible. 是的,这是可能的。 You need to build your C++ library using the Android NDK.
您需要使用Android NDK构建C ++库。 The new link https://developer.android.com/ndk/index.html
新链接https://developer.android.com/ndk/index.html
Yes you can. 是的你可以。 As previous posters mentioned you build your C++ library using the NDK and use JNI to call it from Java
如前所述,您提到使用NDK构建C ++库并使用JNI从Java调用它
If you're planning to make several C++ classes accessible you can use SWIG to automatically generate the JNI layer for you 如果您计划可以访问多个C ++类,则可以使用SWIG自动为您生成JNI层
我不知道它在Android中是否完全相同,但这是一个很棒的教程,帮助我在纯Java中与c ++集成http://www.javaworld.com/javaworld/javatips/jw-javatip17.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.