Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call C++ library from Java in Android

Tags:

java

c++

android

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.

like image 961
Agnel Kurian Avatar asked Jan 25 '12 18:01

Agnel Kurian


2 Answers

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     |
+++++++++++++++++++++++++++++++++++
like image 88
Alok Save Avatar answered Oct 06 '22 14:10

Alok Save


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

like image 41
hopia Avatar answered Oct 06 '22 16:10

hopia