Search code examples
androidc++jna

Best Architecture for C++ Libraries used in Android


I am compiling a c++ library to be used on my Android device.

In compiling the library I did not take into account the architecture I was building the library for.

As a result I have a 64 bit dynamically linked shared library x86_64 which only works on 64 bit systems.

I intend to link this library to my android device using the JNA tool.

What is the appropriate way to compile my c++ library for android architecture and JNA.


Solution

  • You must use the Android NDK.

    Depending on the target architecture, you must select the appropriate toolchain/cross-compiler, e.g. ARM, MIPS or x86.

    See also Getting Started with the NDK


    JNI or JNA have nothing to do with how the library is built. You must build the library for your target architecture, so it can be used on your phone or tablet.

    To access this library from Java, you may use either JNI or JNA.

    With JNI, you must implement glue code in C/C++. With JNA on the other side, you do more or less the same, but you use an existing library (libffi) and implement the glue code in Java. This is done dynamically at runtime and may be thought of something like reflection for a library.