Import custom SO file into AOSP

After this tutorial, I created the AOSP system service: 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 that my code can access it.

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

android.mk content:

LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE:= my_lib LOCAL_MODULE_TAGS := optional include $(BUILD_SHARED_LIBRARY) 

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

I got this error:

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

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

So where should I place the my_lib.so file? and does it need android.mk? maybe i should register it somewhere in the system?

Thanks in advance!

+4
source share
1 answer

So the answer was pretty simple. I really need to copy my library to the system image in the system / lib folder, because the make command does not 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 the file full.mk. this location: android source / build / target / product also put my_lib.so next to it (as seen along the way)

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

+9
source

Source: https://habr.com/ru/post/1488506/


All Articles