0

In Android.mk, how can I specify those lib<xxx>.so?

If I build a share library named libfoo.so, and it needs an external dynamic-linked library libgnustl_shared.so(may not exist in obj/local/<arch>), when I need to deliver our products(libfoo.so and libgnustl_shared.so). I must copy(install) both of them.

My Android.mk is:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := igslib_rtc_timer
LOCAL_SRC_FILES := ../../../out/lib$(LOCAL_MODULE).so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := igslib_util
LOCAL_SRC_FILES := ../../../out/lib$(LOCAL_MODULE).a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := project

LOCAL_SRC_FILES := \
    ../../main.cpp \

LOCAL_C_INCLUDES += ../../../interface ../../
LOCAL_LDLIBS += -llog
LOCAL_CPP_FEATURES += exceptions

LOCAL_STATIC_LIBRARIES += igslib_util 
LOCAL_SHARED_LIBRARIES += igslib_rtc_timer

include $(BUILD_SHARED_LIBRARY)

install:<libs>
    cp $^ <install_dir>

I need the variable <libs>, and it represents libigslib_rtc_timer.so and libproject.so. Any one knows?

naive231
  • 1,360
  • 1
  • 11
  • 28

1 Answers1

0

Please see

Android NDK - make two native shared libraries calling each other

multiple (my and 3rd-party) native libraries in Android NDK

Using a prebuilt native binary in android app (there are links)

Basically, to create multiple libraries you just concatenate the .mk files (or include them from the main .mk)

include abc.mk
include xyz.mk

and since each .mk starts with CLEAR_VARS:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := abc
LOCAL_LDLIBS := -llog

they do not affect each other. And everything found in libs/ will go to the apk.

You will need to hard-code loading the libraries in the order that would resolve dependencies:

static { // calling from a static initializer is important!!!
    System.loadLibrary("abc"); // libabc.so does not depend on libxyz.so
    System.loadLibrary("xyz"); // libxyz.so can depend on libabc.so
}

UPDATE:

According to multiple (my and 3rd-party) native libraries in Android NDK ,

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := random
LOCAL_SRC_FILES := librandom.so
include $(PREBUILT_SHARED_LIBRARY)

will copy the existing library from the source location to libs/. You do not need to specify any installation steps, they always are the same: Android copies everything from the lib/ folder in the apk (yes, this time lib, not libs) to your app's folder.

But there is one exception: this is true only for user applications, Android believes that for system applications (installed via placing them is /system/app on rooted devices and placed there by the firmware manufacturer on non-rooted devices) the libraries are installed by the app manufacturer (that is, either an installation script installs the libraries, or the application itself does this on its first run, or the library is a part of firmware).

Community
  • 1
  • 1
18446744073709551615
  • 16,368
  • 4
  • 94
  • 127