Search code examples
androidandroid-ndkandroid.mk

How to write the Android.mk script?


jni/
    Android.mk     -> libmyso.so
    folder1/
        Android.mk  -> libso1.so
    folder2/
        Android.mk  -> libso2.so

How to compile the libso1.so and libso2.so into the libmyso.so? Thus, I can only load libmyso.so in the java code, and needn't load libso1.so and libso2.so respectively.


Solution

  • If libso1.so and libso2.so are dependencies of libmyso.so (e.g. declared via LOCAL_SHARED_LIBRARIES in Android.mk, they will be loaded automatically on Android 5.0 - the fact that you need to load them in reverse order (loading first the dependencies, then libmyso.so itself) is only a limitation of the linker in old Android versions.

    If you just want to have one single .so file that contains all the code, change the Android.mk for libso1.so and libso2.so to do BUILD_STATIC_LIBRARY instead of BUILD_SHARED_LIBRARY, and refer to them via LOCAL_STATIC_LIBRARIES instead of LOCAL_SHARED_LIBRARIES. Then they will be built in and you only have one single .so file to distribute and load.