我的项目如下:
project/jni/Android.mk
project/jni/libA/Android.mk
project/jni/libB/Android.mk
project/lib/armeabi/libA.so
project/lib/armeabi/libB.so
我的libA和libB在我的主Android.mk上设置为预建的库,因为我不希望每次构建我的主Android.mk时都构建它们。这就是我所拥有的:
LOCAL_PATH := $(call my-dir)
###########################################
# Declare the prebuilt A library
###########################################
include $(CLEAR_VARS)
LOCAL_MODULE := A-prebuilt
LOCAL_SRC_FILES := ../lib/$(TARGET_ARCH_ABI)/libA.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libA
include $(PREBUILT_SHARED_LIBRARY)
###########################################
# Declare the prebuilt B library
###########################################
include $(CLEAR_VARS)
LOCAL_MODULE := B-prebuilt
LOCAL_SRC_FILES := ../lib/$(TARGET_ARCH_ABI)/libB.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libB/include
include $(PREBUILT_SHARED_LIBRARY)
###########################################
# Declare our main module
###########################################
include $(CLEAR_VARS)
LOCAL_MODULE := libjnimain
LOCAL_SRC_FILES := \
main.c
# for logging
LOCAL_LDLIBS += -llog
# include the prebuilt libraries
LOCAL_SHARED_LIBRARIES := \
A-prebuilt \
B-prebuilt
#This will include all Android.mk files in sub-directories
#of the current build file's path.
include $(call all-subdir-makefiles)
include $(BUILD_SHARED_LIBRARY)
我遇到的主要问题是构建预构建库。我似乎无法通过调用他们的Android.mk来构建libA或libB,因为当我执行主要的Android.mk被调用时。任何帮助将不胜感激。
答案 0 :(得分:11)
顾名思义,预构建的库永远不会构建(它们已经构建完成)。如果您需要再次构建预构建的库,则需要使用BUILD_SHARED_LIBRARY包含其源并更改Android.mk以使用这些源再次构建这些模块。但是,您可以将整个库源代码树包含到libs
文件夹中,并将其包含在Android.mk中。
请注意,您添加的库仅在其源更改时生成,并且不会受到其他模块更改的影响。
一个基本的例子如下:
首先是项目的布局。有3个模块:
文件布局:
sdk@AndroidDev:~/ndk/sources/getver$ find jni/
jni/
jni/getver.c
jni/libs
jni/libs/libver
jni/libs/libver/compiled_ver.c
jni/libs/libver/Android.mk
jni/libs/libver/ver.h
jni/libs/libmagic.so
jni/libs/Android.mk
jni/Android.mk
接下来,顶级Android.mk(它在jni /中):
sdk@AndroidDev:~/ndk/sources/getver$ cat jni/Android.mk
LOCAL_PATH := $(call my-dir)
my_LOCAL_PATH := $(LOCAL_PATH)
# Include all libs (built and prebuilt)
include $(LOCAL_PATH)/libs/Android.mk
# Build my executable
LOCAL_PATH := $(my_LOCAL_PATH)
include $(CLEAR_VARS)
LOCAL_MODULE := getver
LOCAL_SRC_FILES := getver.c
LOCAL_SHARED_LIBRARIES= ver magic
include $(BUILD_EXECUTABLE)
jni / libs / Android.mk,包含所有库:
sdk@AndroidDev:~/ndk/sources/getver$ cat jni/libs/Android.mk
LOCAL_PATH := $(call my-dir)
# Prebuilt Lib
include $(CLEAR_VARS)
LOCAL_MODULE := magic
LOCAL_SRC_FILES := libmagic.so
include $(PREBUILT_SHARED_LIBRARY)
# Lib to be built as part of building process.
include $(CLEAR_VARS)
include $(LOCAL_PATH)/libver/Android.mk
最后,libver.so的Android.mk(jni / libs / libver / Android.mk):
sdk@AndroidDev:~/ndk/sources/getver$ cat jni/libs/libver/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ver
LOCAL_HDR_FILES := ver.h
LOCAL_SRC_FILES := compiled_ver.c
include $(BUILD_SHARED_LIBRARY)
在上面的例子中,libmagic.so永远不会被构建,因为它是一个预构建的lib。但是,每次libver源更改时都会构建libver.so。 如果getver源更改,则不会重建。下面的插图示例(我使用 touch 命令来模拟getver.c源代码中的更改):
第一次构建:
sdk@AndroidDev:~/ndk/sources/getver$ ../../ndk-build
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile thumb : getver <= getver.c
Compile thumb : ver <= compiled_ver.c
SharedLibrary : libver.so
Executable : getver
Install : getver => libs/armeabi/getver
Prebuilt : libmagic.so <= jni/libs/
Install : libmagic.so => libs/armeabi/libmagic.so
Install : libver.so => libs/armeabi/libver.so
模拟getver模块源的编辑:
sdk@AndroidDev:~/ndk/sources/getver$ touch jni/getver.c
重建(注意libver.so 不重建):
sdk@AndroidDev:~/ndk/sources/getver$ ../../ndk-build
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile thumb : getver <= getver.c
Executable : getver
Install : getver => libs/armeabi/getver
Install : libmagic.so => libs/armeabi/libmagic.so
Install : libver.so => libs/armeabi/libver.so
模拟libver.so来源的编辑
sdk@AndroidDev:~/ndk/sources/getver$ touch jni/libs/libver/compiled_ver.c
重建(通知getver重建,因为它取决于libver.so:
sdk@AndroidDev:~/ndk/sources/getver$ ../../ndk-build
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile thumb : ver <= compiled_ver.c
SharedLibrary : libver.so
Executable : getver
Install : getver => libs/armeabi/getver
Install : libmagic.so => libs/armeabi/libmagic.so
Install : libver.so => libs/armeabi/libver.so
答案 1 :(得分:0)
您可以在更高级别的Android.mk文件中使用以下内容来递归遍历目录。您将它放在project / jni / Android.mk中,然后进入libA和libB并处理其中的Android.mk文件。
include $(call all-subdir-makefiles)