Where to place .so file so that it gets included in the final build

有些话、适合烂在心里 提交于 2019-12-06 07:26:58

Your module rules are a problem.

when you have a pre-built library with LOCAL_MODULE := customutil, then the linker will get the additional flag -lcustomutil. Thus your LOCAL_SRC_FILES := needs to be LOCAL_SRC_FILES := libcustomutil.so

Thus 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 according to the library name.

By default, for prebuilts, LOCAL_SRC_FILES are relative to your current LOCAL_PATH definition, so if your Android.mk is under $PROJECT/jni/Android.mk, you should put it at $PROJECT/jni/xyz.so

The name should also be probable libxyz.so instead of xyz.so (though that might work without the lib prefix).

If you plan to support several CPU ABIs, try to use a sub-directory, 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.

I added my prebuilt .so file in external folder of AOSP source code as following:-

Step 1 :- I have created one folder(let say myLibs) inside external folder of AOSP then I added my .so file in it and added following code in 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 my shared libs name in Frameworks/base/core/jni/Android.mk file in LOCAL_SHARED_LIBRARIES section.

Now it is generation my .so file in out/target/product/generic/obj/lib folder

Thanks Happy Coding...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!