Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

android ndk - NDK: How to include Prebuilt Shared Library Regardless of Architecture

I am working on porting Box2D to learn a little more about android porting.

I can get the project compiling and I see the following....

ls libs/

armeabi armeabi-v7a

Now I want to do something like this but i don't know how to make it smart enough to choose arch (say I wanted to add x86). How do I include the .so without hard coding the .so path to a spec arch?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Simply define which architectures you would like to support in android.mk and Application.mk as described in the NDK documentation (APPLICATION-MK.html and PREBUILTS.html):

V. ABI Selection of prebuilt binaries:

As said previously, it is crucial to provide a prebuilt shared library that is compatible with the targeted ABI during the build. To do that, check for the value of TARGET_ARCH_ABI, its value will be:

armeabi => when targeting ARMv5TE or higher CPUs armeabi-v7a => when targeting ARMv7 or higher CPUs x86 => when targeting x86 CPUs mips => when targeting MIPS CPUs

Note that armeabi-v7a systems can run armeabi binaries just fine.

Here's an example where we provide two versions of a prebuilt library and select which one to copy based on the target ABI:

include $(CLEAR_VARS)
LOCAL_MODULE := foo-prebuilt
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libfoo.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)

Here. we assume that the prebuilt libraries to copy are under the following directory hierarchy:

Android.mk            --> the file above
armeabi/libfoo.so     --> the armeabi prebuilt shared library
armeabi-v7a/libfoo.so --> the armeabi-v7a prebuilt shared library
include/foo.h         --> the exported header file

NOTE: Remember that you don't need to provide an armeabi-v7a prebuilt library, since an armeabi one can easily run on the corresponding devices.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...