Where to place the .so file so that it will be included in the final build
I have a .so file that is referenced by another project in the AOSP system package. To make the link possible, I created a new project in AOSP / external package with two files in it: Android.mk and xyz.so. Android.mk looks like this.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := customutil
LOCAL_SRC_FILES := xyz.so
include $(PREBUILT_SHARED_LIBRARY)
At compile time, it gives me the following error.
make: * No rule to create target out/target/product/crespo/obj/lib/customutil.so', needed by
out / target / product / crespo / obj / EXECUTABLES / abc_agent_intermediates / LINKED / abc_agent '. Stop.
Where should I store the xyz.so file or what changes should I make so that when the AOSP is created, it doesn't trigger this error?
Sushil
source to share
Your module rules are the problem.
when you have a pre-built library with LOCAL_MODULE := customutil
then the linker will get an extra flag -lcustomutil
. So yours LOCAL_SRC_FILES :=
should beLOCAL_SRC_FILES := libcustomutil.so
So the Android.mk section should be:
# Prebuilt Lib
include $(CLEAR_VARS)
LOCAL_MODULE := xyx
LOCAL_SRC_FILES := libxyz.so
include $(PREBUILT_SHARED_LIBRARY)
This also means that you need to rename the library appropriately, or set the module name to match the library name.
source to share
The defaults for prebuilts LOCAL_SRC_FILES are relative to your current definition of LOCAL_PATH, so if your Android.mk is under $PROJECT/jni/Android.mk
you should put it in$PROJECT/jni/xyz.so
The name should also be likely libxyz.so instead of xyz.so (although this might work without the lib prefix).
If you plan on supporting multiple CPU ABIs, try using a subdirectory as in:
include $(CLEAR_VARS)
LOCAL_MODULE := libxyz
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libxyz.so
include $(PREBUILT_SHARED_LIBRARY)
And place the files under:
$PROJECT/jni/armeabi/libxyz.so
$PROJECT/jni/armeabi-v7a/libxyz.so
$PROJECT/jni/x86/libxyz.so
...
Finally, you can also use an absolute path for LOCAL_SRC_FILES and the build system will pick the file from there.
source to share
I added the presobu.so file to the external AOSP source folder as follows: -
Step 1: - I created one folder (let's say myLib) inside the external AOSP folder then I added the .so file to it and added the following code to the 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)
Then I added the name of my shared libs to the Frameworks / base / core / jni / Android.mk file under LOCAL_SHARED_LIBRARIES.
Now this is generating my .so file in out / target / product / generic / obj / lib folder
Thanks Happy coding ...
source to share