Search code examples
eclipsec++11android-ndkshared-librariesmultiplatform

Build NDK with included shared library on multiple platforms


I have built a C++ shared library with NDK builder in Eclipse (firestly creating a JNI project with no MainActivity), which provided as output the different platforms that I have specified in the Application.mk file. The output is in the /obj/local/ directory, spread over the platforms subdirectories (armabi, mips, ... i.e. all the platforms that I have specified in the above file). Now, I want to use this shared library inside an Android native project, where my shared library is called inside a project's native library (therefore it is about "native-calling-native"). If I build both the shared library and the Android native aplication for just one type of platform (let's say "armeabi"), everything works fine. My question is how to create the make files, Android.mk and Application.mk, of the Android native project so that to build for ALL the platforms. I suppose the key is in the Android.mk file, which, for just one platform build it looks like this (on Linux, for the .so type, C++11 for info):

LOCAL_PATH := $(call my-dir)

# Define the shared library module used by the calling JNI C++ module
include $(CLEAR_VARS)

LOCAL_SRC_FILES := libs/libCreateSharedWithJni.so
LOCAL_MODULE := CreateSharedWithJni
LOCAL_EXPORT_C_INCLUDES := libs/CreateSharedWithJni.h
include $(PREBUILT_SHARED_LIBRARY)

# Define the calling JNI C++ module
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_MODULE    := finalmodule
LOCAL_SRC_FILES := CppJniCallShared.cpp

LOCAL_SHARED_LIBRARIES := libCreateSharedWithJni

include $(BUILD_SHARED_LIBRARY)

Thanks!


Solution

  • Got it! In the above Android.mk file just change the line as following

    LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libCreateSoWithJni.so
    

    i.e. using the $(TARGET_ARCH_ABI) in the path drives the builder to process all platforms specified in the Application.mk APP_ABI variable.