Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Prebuilt Shared Library in Android AOSP

I want to use a pre-built shared library in AOSP. The library is defined in Android.mk like this:

include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_TAG := optional
LOCAL_MODULE_PATH := system/lib
LOCAL_SRC_FILE := system/lib/foo.so
include $(BUILD_PREBUILT)

During build, a folder out/target/product/mako/obj/SHARED_LIBRARIES/foo_intermediates/export_include was created.

However, the build failed with error message that out/target/product/mako/obj_arm/SHARED_LIBRARIES/foo_intermediates/export_include cannot be found.

Note the difference between "obj" and "obj_arm". What caused the problem?

like image 299
JustWonder Avatar asked Mar 21 '15 06:03

JustWonder


People also ask

What is Android shared library used for?

2.1. Similar to the traditional Linux model, shared libraries in Android are relocatable ELF files that map to the address space of the process when loaded. To save memory and avoid code duplication, all shared objects shipped with Android are dynamically linked against the Bionic libc library [23].

Where are shared libraries in Android?

system/vendor/lib.


Video Answer


1 Answers

This is two-target build (arm and arm64), so there are two obj folders, one for 32-bit arm and the other for 64-bit arm.

I need to define the library as follows:

include $(CLEAR_VARS)
LOCAL_MODULE := libfoo
LOCAL_MODULE_SUFFIX :=.so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_TAGS := optional
LOCAL_PRELINK_MODULE := false
ifdef TARGET_2ND_ARCH
LOCAL_MULTILIB := both
LOCAL_MODULE_PATH_64 := system/lib64
LOCAL_SRC_FILES_64 := system/lib64/libfoo.so
LOCAL_MODULE_PATH_32 := system/lib
LOCAL_SRC_FILES_32 := system/lib/libfoo.so
else
LOCAL_MODULE_PATH := system/lib
LOCAL_SRC_FILES := system/lib/libfoo.so
endif
include $(BUILD_PREBUILT)
like image 116
JustWonder Avatar answered Oct 16 '22 11:10

JustWonder