Reputation: 59516
Is it possible to call a C++ library from an Android app? 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. 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.
Upvotes: 14
Views: 16947
Reputation: 5006
Yes, it's possible. You need to build your C++ library using the Android NDK. The new link https://developer.android.com/ndk/index.html
Upvotes: 8
Reputation: 4115
Yes you can. As previous posters mentioned you build your C++ library using the NDK and use JNI to call it from Java
If you're planning to make several C++ classes accessible you can use SWIG to automatically generate the JNI layer for you
Upvotes: 2
Reputation: 1725
I don't know if its exactly the same in Android, but this is a great tutorial that helped me in pure java integration with c++ http://www.javaworld.com/javaworld/javatips/jw-javatip17.html
Upvotes: 0
Reputation: 206616
You need to write an Java Native Interface(JNI) to be able to call the native(c/c++) libraries from Android Java code.
The hierarchy is like:
+++++++++++++++++++++++++++++++++++
| Android Application |
+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
| Android Application Framework |
+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
| Java Native Interface |
+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
| C/C++ Native Libraries |
+++++++++++++++++++++++++++++++++++
Upvotes: 12