我正在使用Android NDK构建C ++库来构建Android项目。 我使用带有Sequoyah插件的Eclipse。 一切都设置好了,也工作正常。
但是,我遇到了构建配置的问题。 您可以通过右键单击项目->属性,然后进入C / C ++ Build部分来管理构建配置。 这使您可以创建大多数C ++库某种方式依赖的传统Debug和Release构建。
以下是我的“调试”配置示例:
V=1 NDK_DEBUG=1 NDK_APPLICATION_MK=config/debug/Application.mk
这些工具很好用,但是当我在配置之间切换时,它不会触发我正在构建的库的重建。对于像Visual Studio这样的工具,每个构建配置都会转储到不同的目录中,这是可以预期的,但是在Eclipse中,所有东西都会被倾倒到同一个目录中。我被迫实际更改相关源文件才能触发重新构建。因此,最终的结果是,我在使用调试配置运行程序,但是链接到了在Release中构建的库。
因此我的问题是:是否有一种方法可以强制NDK在更改配置时重新构建库? 我知道我可以添加-B命令,但那会每次都重建所有库,而且每次都会这样。如果我可以只为一个特定库(在本例中为libBootInfo)执行重建,我将会满意。
下面是我的根Android.mk文件的内容:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := game$(MY_BUILD_CONFIG_EXTENSION)
# Include files are relative to the NDK root directly (fix by prepending with $(LOCAL_PATH))
# Source files are relative $(LOCAL_PATH)
#LOCAL_LDLIBS := -landroid
# Add all source file names to be included in lib separated by a whitespace
LOCAL_SRC_FILES := ../../../../../../engine/code/main/mainandroid.cpp
# Module dependencies are expressed with LOCAL_STATIC_LIBRARIES and LOCAL_SHARED_LIBRARIES.
# we're building the "main" entry point, so it doesn't depend on much
LOCAL_STATIC_LIBRARIES := libDebug$(MY_BUILD_CONFIG_EXTENSION) libCore$(MY_BUILD_CONFIG_EXTENSION)
include $(BUILD_SHARED_LIBRARY)
$(call import-module,libBdCore)
$(call import-module,libDebug)
##################################################################
## In addition to the core game library, we also build another
## *.so file here: "libBootInfo". This very small library is used
## by Java to find out which version of game to load based on
## the current build configuration.
##
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libBootInfo
# Add all source file names to be included in lib separated by a whitespace
# TODO: This path is relative to "android-ndk\build\core" which seems
# different from the LOCAL_SRC_FILES in game above. It seems like
# the build process leaves us in a different directory than we started.
# We make need to look into a way to make sure that this path always
# works regardless of what came before it.
#
LOCAL_SRC_FILES := ../../../../engine/code/main/bootinfo.cpp
include $(BUILD_SHARED_LIBRARY)
Android.mk
文件中,构建 libBootInfo 的部分不应重新计算LOCAL_PATH := $(call my-dir)
。这是因为$(call my-dir)
实际上会带来在此语句之前包含的最后一个 make file 的路径。如果你将所有 libBootInfo 部分移到Android.mk
的顶部,它将可以平稳地工作。 - Alex CohnLOCAL_C_INCLUDES
是相对于_当前目录_的,通常是项目根目录。 - Alex Cohn