简体   繁体   中英

importing custom SO file to AOSP

I've built an AOSP system service following this tutorial: http://www.androidenea.com/2009/12/adding-system-server-to-android.html

Now I want to use a pre-compiled.so file and cannot figure out where to put it so my code will be able to access it.

so, i created a folder at framewaork/base/libs/my_folder/ and put there two files: my_lib.so android.mk

the content of the android.mk is:

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE:= my_lib
LOCAL_MODULE_TAGS := optional

include $(BUILD_SHARED_LIBRARY)

the make ran without errors, but when the code tried to load the library via: System.loadLibrary("my_lib");

i got this error:

06-27 13:58:55.581: E/AndroidRuntime(806): Caused by: java.lang.UnsatisfiedLinkError: Library my_lib not found; tried [/vendor/lib/my_lib.so, /system/lib/my_lib.so]

so i added the so file to out/target/product/generic/system/lib but got the same error.

so where should i place the my_lib.so file? and is an android.mk needed for it? maybe i should register it somewhere on the system?

Thanks in advance!

So the answer was quite simple. I really need to copy my lib to the system image, to the system/lib folder, because the make command doesn't copy it from out/target/product/generic/system/lib to system.img

the trick is to add this line

  PRODUCT_COPY_FILES += $(LOCAL_PATH)/my_lib.so:system/lib/my_lib.so

to full.mk file. it's location is: android-source/build/target/product also put the my_lib.so near it (as seen by the path)

if you are planning to run the image on a real device, add this line after the device name definition. f.ex.if you are running on Nexus 4, put it at android-source/device/lge/mako/full_mako.mk

in my case, solved this problem by creating Android.bp file in the repo where i put my prebuilt libraries, then i added them as product packages in the product mk file. this is an example:

Android.bp:

cc_prebuilt_library {
name: "product_package_name_in_MK_file",
relative_install_path: "sub_lib/sub_sub_lib",
stem: "output_file_name", // .so will be added automatically to out file name.
compile_multilib: "both",
multilib: {
lib32: {
srcs: ["path for src 32bit lib"],
},
lib64: {
srcs: ["path for src 64bit lib"],
},
},
strip: {
none:true,
},
allow_undefined_symbols: true,
check_elf_files: false,
vendor: true,
enabled: true,
}

product_mk file:

...

PRODUCT_PACKAGES += product_package_name_in_MK_file

...

You can add your prebuilt library in Android AOSP source code and it be a part of your AOSP System Image. I am describing step by step procedure for it.

Step 1 Create a folder ( let say myLibs) inside external folder of AOSP source code.

external folder of AOSP source code refers to external open source libraries. That means libraries that the Android platform depend upon but that are not primarily developed and maintained by the Android open source project.

examples are webkit for the browser, FreeType for fonts, SqlLite for databases and so on. As more features are added to Android, more of these libraries are included in external.

Step 2 Create a Android.mk file

Create a Android.mk file inside your folder(let say myLibs) and copy your .so file in it.
You can use following content for your android.mk file

# Prebuilt Lib
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libMyabc # your lib name
LOCAL_SRC_FILES := libMyabc.so
# your lib .so file name
include $(BUILD_SHARED_LIBRARY)

Step 3 Add your library in Framework

In final step you have to add your library in Android AOSP framework makefile so that it will recognise and build as a part of System image.
You find Framework Android.mk file on following location
/android_aosp_sourcecode_download_folder/fram enter code here eworks/base/core/jni/

Open Android.mk file and add your library in following section
LOCAL_SHARED_LIBRARIES := \\
You can put your library name in that section example libMyabc \\

That's it... now make it (make -j4) and you find your added so file in following folder
/android_aosp_sourcecode_download_folder/out/target/product/generic/obj/lib
with file name like :- libMyabc.so and libMyabc.so.toc
and you also found it in system/lib folder
/android_aosp_sourcecode_download_folder/out/target/product/system/lib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM