3

I try to set up an Android NDK build based on CMake scripts, which dynamically create the required Android make files. While I can't use the JNI folder structure I split the build process in several separated make scripts:

1st Create root Android.mk file located in project root:

#ANDROID ROOT MAKEFILE

LOCAL_PATH := D:/binrev/repository/bar
include $(CLEAR_VARS)

MY_LOCAL_CFLAGS := -DDEBUG
include D:/binrev/repository/bar/src/Android.mk

2nd Create source Android.mk file in project source folder and perform module build:

$(info "[INFO] Source Makefile invoked")

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE    := bar
LOCAL_C_INCLUDES:= D:/binrev/repository/bar/include
LOCAL_SRC_FILES :=  bar.cpp

ifeq (debug,"debug")
   MY_LOCAL_CFLAGS := -DDEBUG
endif

ifeq (false,true)
   LOCAL_ARM_MODE := arm
endif

LOCAL_EXPORT_C_INCLUDES := D:/binrev/repository/bar/include

LOCAL_LDLIBS := -llog 
LOCAL_LDLIBS += -landroid

LOCAL_STATIC_LIBRARIES += foo 

ifeq (OFF, ON)
   include $(BUILD_SHARED_LIBRARY)
else
   include $(BUILD_STATIC_LIBRARY)
endif

Basicly this mechanism works and I could compile my sources, but I fail if I try to include a Prebuild of a library. I tried the following ways to include a pre-build of a static library (with modified source/include definitions):

include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := lib/android/$(TARGET_ARCH_ABI)/libfoo.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY) 

1st Prebuild definition in source Android.mk file 2nd Call import-module mechanism and add Prebuild Android.mk file to prebuild-lib 3rd Prebuild definition in root Android.mk file

[Edit:] Here is the snipped of the call-import test which also fail: $(info "[INFO] Source Makefile invoked")

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE    := bar
LOCAL_C_INCLUDES:= D:/binrev/repository/bar/include
LOCAL_SRC_FILES :=  bar.cpp

ifeq (debug,"debug")
    MY_LOCAL_CFLAGS := -DDEBUG
endif

ifeq (false,true)
    LOCAL_ARM_MODE := arm
endif

LOCAL_EXPORT_C_INCLUDES := D:/binrev/repository/bar/include

LOCAL_LDLIBS := -llog 
LOCAL_LDLIBS += -landroid

LOCAL_STATIC_LIBRARIES += foo 

ifeq (ON, ON)
   include $(BUILD_SHARED_LIBRARY)
else
   include $(BUILD_STATIC_LIBRARY)
endif

$(call import-module, external-deps/foo)

In each case the Script with the prebuild-definition is invoked, but the prebuild is not performed. When my NDK build has been compleded, the prebuild library and objects are not copied to my obj folder. It seems to me that the prebuild is completely ignored. But the path to prebuild sources are correct, otherwise the compile fails with missing file error.

You could get the complete source of this test implementation here: [Test projects][1]https://sourceforge.net/projects/binrevengine/files/publications/

Hint: The bar project is the project which tries to prebuild the foo project. The foo project contains the prebuild sources.

The added tests projects could be build by your own using MinGW64 with GCC 4.7/4.8 in handshake with CMake and pre installed NDK (using r8e).

I completly get lost and running out of ideas ... Thanks for any help.

4

2 回答 2

0

为了排除可能的缺陷来源,我将 Android make 文件简化为最简单的情况,而不使用这些文件的 CMake 生成器:

LOCAL_PATH := D:/binrev/repository/bar
include $(CLEAR_VARS)

LOCAL_MODULE    := foo-prebuilt
LOCAL_SRC_FILES := external-deps/foo/lib/android/$(TARGET_ARCH_ABI)/libfoo.a
include $(PREBUILT_STATIC_LIBRARY)


include $(CLEAR_VARS)           
LOCAL_MODULE    := bar
LOCAL_C_INCLUDES:= D:/binrev/repository/bar/include
LOCAL_C_INCLUDES+= D:/binrev/repository/bar/external-deps/foo/include
LOCAL_SRC_FILES := src/bar.cpp


LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += -landroid 

LOCAL_SHARED_LIBRARIES := foo-prebuilt
include $(BUILD_SHARED_LIBRARY)

和:

LOCAL_PATH := D:/binrev/repository/foo

include $(CLEAR_VARS)

LOCAL_MODULE    := foo
LOCAL_C_INCLUDES:= D:/binrev/repository/foo/include
LOCAL_SRC_FILES := src/foo.cpp

LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += -landroid 

include $(BUILD_STATIC_LIBRARY)

故障依然存在。未执行 foo 库的预构建。我还排除了 MinGW64 作为可能的缺陷来源,如果我尝试使用 Windows 命令行构建项目,则会导致相同的问题。共享库已构建,但未执行预构建。

我多次检查我的源代码和脚本,但找不到任何失败。有什么想法可能是错误或遗漏的吗?

于 2013-05-22T09:07:25.513 回答
0

Android 构建系统不会在没有被共享库使用的情况下构建静态库。只需创建一个虚拟共享库,将您的静态库作为依赖项,瞧:

include $(CLEAR_VARS)
LOCAL_MODULE := dummy
LOCAL_PATH := $(LOCAL_PATH)
LOCAL_SRC_FILES := dummy.c
LOCAL_STATIC_LIBRARIES := foo
include $(BUILD_SHARED_LIBRARY)
于 2013-05-17T20:59:39.863 回答