2

The problem:

I have a native Android application that is compiled for x86 and arm, armv7a.
The app also links to a pre-shared library.
That pre-shared library is also compiled for x86, arm, and armv7a. So there are 3 lib.so files.

What must I do in the Android.mk/Application.mk to link to the appropriate *.so file given the architecture it is being compiled for?

That is, when the build system is compiling for arm, it should link to the libs/armeabi/lib.so.
Likewise, when the Build system is compiling for x86, it should use the libs/x86/lib.so file.

I believe the alternative might be a more complex build script but I'm shooting for the simple solution first, if it exists. Thanks!

The answer Unfortunately my query skills were not very good and shortly after posting, I found the question and answer already on SO:
How can i Link prebuilt shared Library to Android NDK project?

To summarize:
Prebuilt shared libraries, compiled for different platforms, should all be named the same and go under the jni/${ARCH}/ directory.

That is, the structure should appear as so: jni/x86/libtest.so jni/armeabi/libtest.so jni/armeabi-v7a/libtest.so

Community
  • 1
  • 1
Cookster
  • 1,463
  • 14
  • 21

1 Answers1

3

You should use the $(TARGET_ARCH_ABI) flag, for example:

include $(CLEAR_VARS)
LOCAL_MODULE := mylib-prebuilt 
LOCAL_SRC_FILES := ../path_to_prebuilt_folder/libs/$(TARGET_ARCH_ABI)/libmylib.so 
include $(PREBUILT_SHARED_LIBRARY)
thiagolr
  • 6,909
  • 6
  • 44
  • 64
  • If you use the local_module name Android make will auto-pick up the libraries based on platform under JNI/{arch}. I like your solution better, however, because it spells it out to the developer what exactly is being baked into the library. – Cookster Jun 18 '13 at 16:14