Call C++ library from Java in Android

前端 未结 4 988
故里飘歌
故里飘歌 2020-12-28 08:54

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

相关标签:
4条回答
  • 2020-12-28 09:11

    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

    0 讨论(0)
  • 2020-12-28 09:12

    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

    0 讨论(0)
  • 2020-12-28 09:12

    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     |
    +++++++++++++++++++++++++++++++++++
    
    0 讨论(0)
  • 2020-12-28 09:21

    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

    http://www.swig.org/index.php

    0 讨论(0)
提交回复
热议问题