Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

c++ - Using my own prebuilt shared library in an Android NDK project

I came across this post that is almost what I need:

How to compile a static library using the Android NDK?

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.

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?

And if I change Android.mk in the separate project to read:

include $(BUILD_SHARED_LIBRARY)

and include it like this in the main project:

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...