Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 500
Arkady Avatar asked Jun 27 '13 14:06

Arkady


People also ask

How do you add so file in Aosp?

As more features are added to Android, more of these libraries are included in external. Create a Android.mk file inside your folder(let say myLibs) and copy your . so file in it. 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.

Where do you keep .so files?

An . so file is a compiled library file. It stands for "Shared Object" and is analogous to a Windows DLL. Often, package files will place these under /lib or /usr/lib or some place similar when they're installed.


1 Answers

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

like image 60
Arkady Avatar answered Sep 20 '22 23:09

Arkady