I would like to use a prebuilt shared library (let's call it libmylib.so
) from some AOSP code, for instance in the folder framework/av/media/libmedia
.
Since my target is Nexus 7, I created a new folder device/asus/flo/mylib
, where I put 2 files:
libmylib.so
Android.mk
My first try was to use PREBUILT_SHARED_LIBRARY
in Android.mk
as follow:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libmylib
LOCAL_SRC_FILES := libmylib.so
include $(PREBUILT_SHARED_LIBRARY)
Then, I added the dependency in the libmedia
module (in framework/av/media/libmedia/Android.mk
, I added libmylib
to the LOCAL_SHARED_LIBRARIES
list).
Unfortunately, the build (lunch aosp_flo-eng && make -j4
) failed:
*** No rule to make target `out/target/product/flo/obj/SHARED_LIBRARIES/libmylib_intermediates/export_includes’, needed by `out/target/product/flo/obj/SHARED_LIBRARIES/libmedia_intermediates/import_includes’. Stop.
Therefore, I replaced PREBUILT_SHARED_LIBRARY
by BUILD_PREBUILT
(I don't really understand the difference):
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libmylib
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := libmylib.so
include $(BUILD_PREBUILT)
That way, the build succeeded.
So I flashed the image:
fastboot flashall -w
But unfortunately, the tablet did not boot. adb logcat
printed indefinitely:
E SurfaceFlinger: error posting framebuffer: -22
E qdgralloc: fb_post: FBIOPUT_VSCREENINFO for primary failed, str: Invalid argument
E SurfaceFlinger: error posting framebuffer: -22
E qdgralloc: fb_post: FBIOPUT_VSCREENINFO for primary failed, str: Invalid argument
E SurfaceFlinger: error posting framebuffer: -22
E qdgralloc: fb_post: FBIOPUT_VSCREENINFO for primary failed, str: Invalid argument
If I remove libmylib
from framework/av/media/libmedia/Android.mk
, everything is fine, the tablet boots correctly.
Note that I don't even call the library at this point, the simple fact to declare it as a libmedia
dependency is problematic.
I tried with several .so
(including one that I tested on the tablet with a binary calling a function it exposes, directly in /data/local/tmp
, so the .so
is ok).
I probably missed something. Any clue?
I tested the same thing on Nexus 5, which is fortunately more verbose :)
The problem was that LOCAL_MODULE
and LOCAL_SRC_FILES
didn't use the same lib name (a problem that was not present in my original post, since I wanted to abstract the details).
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libmylib
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := libsomething.so
include $(BUILD_PREBUILT)
The module was libmylib
, but the source file was libsomething.so
.
That way, there was a /system/lib/libsomething.so
, but a dlopen()
failed because /system/lib/libmylib.so
was not found.
Using the same name for both solves the problem:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libsomething
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := libsomething.so
include $(BUILD_PREBUILT)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With