在 Android NDK 项目中使用我自己的预构建共享库 [英] Using my own prebuilt shared library in an Android NDK project
问题描述
我发现这篇文章几乎是我需要的:
I came across this post that is almost what I need:
基本上,我的项目中有某些部分从未更新过,因此我试图避免每次更新 Android.mk 文件以添加内容时都构建它们.
Basically, there are certain parts in my project that are never updated, so I am trying to avoid having them built every single time I update the Android.mk file to add something.
上面的答案显示了如何将一些代码构建到单独的静态库中,但是当我尝试在单独的 Android.mk 文件中预构建上述代码时,它不会自行构建.这似乎有点多余......如果我必须同时构建它们,那么无论如何制作单独的静态库有什么意义?
The above answer shows how to get some of the code built into a separate static lib, but when I try to pre-build the above code in a separate Android.mk file, It won't build by itself. This seems a little redundant... If I have to build them both at the same time, then what's the point of making a separate static lib anyways?
如果我将单独项目中的 Android.mk 更改为读取:
And if I change Android.mk in the separate project to read:
包含 $(BUILD_SHARED_LIBRARY)
include $(BUILD_SHARED_LIBRARY)
并像这样将其包含在主项目中:
and include it like this in the main project:
LOCAL_SHARED_LIBRARIES := libMyaccessories.so
LOCAL_SHARED_LIBRARIES := libMyaccessories.so
然后我得到了对(函数名)的未解析引用,可能是因为它找不到共享库(在调用路径中)
then I get unresolved reference to(function name), probably because it can't find the shared lib(which is in the calling path)
谁能帮我解决这个问题?
Can anyone help me out with this?
推荐答案
在Android.mk的文档中,查看PREBUILT_SHARED_LIBRARY
脚本描述.将 .so 文件放在 lib
(不是 libs
)目录中,并在它旁边写一个 Android.mk 文件,如下所示:
In the documentation of Android.mk, check the PREBUILT_SHARED_LIBRARY
script description. Put the .so file in lib
(not libs
) directory and write an Android.mk file next to it that looks something like:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := Myaccessories
LOCAL_SRC_FILES := libMyaccessories.so
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../jni/include
include $(PREBUILT_SHARED_LIBRARY)
这篇关于在 Android NDK 项目中使用我自己的预构建共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!