预构建静态库失败

时间:2013-05-17 05:22:26

标签: android android-ndk cmake

我尝试设置基于CMake脚本的Android NDK构建,动态创建所需的Android make文件。虽然我无法使用JNI文件夹结构,但我将构建过程拆分为几个独立的make脚本:

第一个创建位于项目根目录中的根Android.mk文件:

#ANDROID ROOT MAKEFILE

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

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

在项目源文件夹中创建源Android.mk文件并执行模块构建:

$(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

基本上这个机制有效,我可以编译我的源代码,但是如果我尝试包含一个库的Prebuild,我就会失败。我尝试了以下方法来包含预构建 静态库(具有修改的源/包含定义):

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) 

源Android.mk文件中的第一个Prebuild定义 第二次调用导入模块机制并将Prebuild Android.mk文件添加到prebuild-lib root Android.mk文件中的第3个预建定义

[编辑:]以下是调用导入测试的剪辑,该测试也失败了:     $(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)

在每种情况下,都会调用带有prebuild-definition的脚本,但是预建 没有执行。当我的NDK构建完成后,prebuild库和 对象不会复制到我的obj文件夹。在我看来,预建是 完全被忽略了但预建源的路径是正确的,否则 编译失败,文件错误丢失。

您可以在此处获得此测试实施的完整来源: [测试项目] [1] https://sourceforge.net/projects/binrevengine/files/publications/

提示:bar项目是试图预建foo项目的项目。       foo项目包含预建源。

添加的测试项目可以由您自己使用MinGW64和GCC 4.7 / 4.8与CMake握手并预先安装NDK(使用r8e)来构建。

我完全迷失了,没有想法...... 谢谢你的帮助。

2 个答案:

答案 0 :(得分: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)

答案 1 :(得分: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命令行构建项目,则会导致同样的问题。共享库是构建的,但预执行不会执行。

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