Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including prebuilt static library in Android build system

I need to build a shared library based on a prebuilt static library. My makefile src/android/external/mycode/Android.mk:

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm
LOCAL_MODULE := libMyStatic
LOCAL_SRC_FILES := libStatic.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := eng
LOCAL_ARM_MODE := arm
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE    := libMyShared
LOCAL_WHOLE_STATIC_LIBRARIES := libMyStatic
include $(BUILD_SHARED_LIBRARY)

I build it by doing: mmm external/mycode and get the error:

make: *** No rule to make target `out/target/product/generic/obj/STATIC_LIBRARIES/libMyStatic_intermediates/libMyStatic.a', needed by `out/target/product/generic/obj/SHARED_LIBRARIES/libMyShared_intermediates/LINKED/libMyShared.so'.  Stop.
make: Leaving directory `/home/test/src/android'

If I do the following manually and run mmm again it works:

cp external/mycode/libStatic.a out/target/product/generic/obj/STATIC_LIBRARIES/libMyStatic_intermediates/libMyStatic.a

If I make an NDK project and use this Android.mk file I think it works right away when calling the ndk-build script. So the problem has something to do with that the libMyStatic.a file is not created and copied to the intermediate folder when I use the Android Build system. Can anyone tell me what I need to setup to make the build system copy the static library to the intermediate folder?

like image 361
Kim Avatar asked Apr 15 '11 13:04

Kim


People also ask

Where do I put Android MK files?

The Android.mk file resides in a subdirectory of your project's jni/ directory, and describes your sources and shared libraries to the build system. It is really a tiny GNU makefile fragment that the build system parses once or more.

What is Local_cflags?

LOCAL_CFLAGS is applied to the current module, and is undefined after an include $(CLEAR_VARS) . APP_CFLAGS is applied to all modules.

What is NDK build?

To compile and debug native code for your app, you need the following components: The Android Native Development Kit (NDK): a set of tools that allows you to use C and C++ code with Android. CMake: an external build tool that works alongside Gradle to build your native library.


2 Answers

modify your mk file

"LOCAL_WHOLE_STATIC_LIBRARIES := libMyStatic"

to

"LOCAL_LDFLAGS += -lMyStatic
like image 173
Benjamin Chung Avatar answered Nov 14 '22 23:11

Benjamin Chung


Try building your static library like this.

include $(CLEAR_VARS)

LOCAL_MODULE := libMyStatic
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_SUFFIX := .a
LOCAL_SRC_FILES := libMyStatic.a

include $(BUILD_PREBUILT)
like image 30
Jason Lin Avatar answered Nov 15 '22 01:11

Jason Lin