现在,我正在一个本地Android项目上工作,我想使用DevIL。
我不想将所有NDK代码都放在一个文件中,因为DevIL需要多个其他库(libpng / libjpeg / ...),而Android.mk最终会变得肿。

我在jni目录中创建了一个名为Devil的子目录。我将DevIl(+库)所需的所有代码都放在此目录中。我还在此目录中创建了一个额外的Android.mk文件。在我的“主要” Android.mk文件中,我添加了$(调用import-module,DevIL)以及:LOCAL_SHARED_LIBRARIES + = libdevil。在DevIL Android.mk中,我创建了一个libdevil模块,并使用LOCAL_EXPORT_C_INCLUDES链接到DevIL头文件。当我将#include放入main.cpp文件时,ndk-build失败,并就所包含的标头抱怨“没有这样的文件或目录”。如果我不将#include放入代码中,则代码可以正常编译,所有共享库都将创建并放入libs文件夹中。我究竟做错了什么?

我的主要Android.mk

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

LOCAL_MODULE            := arm
LOCAL_SRC_FILES         := main.cpp
LOCAL_SHARED_LIBRARIES  += libdevil

include $(BUILD_SHARED_LIBRARY)

 $(call import-module,DevIL)


用于DevIl的Android.mk

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

include cflags.mk

JPEG_SRC_PATH       := Libjpeg/
DEVIL_SRC_PATH      := DevIL/
#many more

#libjpeg
include $(CLEAR_VARS)

LOCAL_MODULE    := libjpeg
LOCAL_C_INCLUDES  :=  ${JPEG_SRC_PATH}
FILE_LIST := $(wildcard $(LOCAL_PATH)/JPEG_SRC_PATH/*.c)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

include $(BUILD_SHARED_LIBRARY)

#many other libraries; basically the same as libjpeg

#libdevil
 include $(CLEAR_VARS)

 LOCAL_MODULE    := libdevil
 LOCAL_EXPORT_C_INCLUDES  :=  \
                          ${DEVIL_SRC_PATH}include \
                          ${DEVIL_SRC_PATH}src-IL/include \
                          #many more

 FILE_LIST := $(wildcard $(LOCAL_PATH)/DEVIL_SRC_PATHsrc-IL/src/*.c)
 LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
 LOCAL_STATIC_LIBRARIES := \
                        libjpeg \
                        #many more
 LOCAL_LDLIBS    += -lz
 include $(BUILD_SHARED_LIBRARY)


cflags.mk文件

LOCAL_CFLAGS    := -DANDROID_NDK
LOCAL_CFLAGS    += -Werror
LOCAL_CFLAGS    += -Wall
LOCAL_CFLAGS    += -Wextra
LOCAL_CFLAGS    += -Wno-strict-aliasing
LOCAL_CFLAGS    += -Wno-unused-parameter
LOCAL_CFLAGS    += -Wno-missing-field-initializers
LOCAL_CFLAGS    += -Wno-multichar
LOCAL_CPPFLAGS := -Wno-type-limits
LOCAL_CPPFLAGS += -Wno-invalid-offsetof
LOCAL_CPPFLAGS += -std=c++11
LOCAL_CFLAGS    += -std=c++11
LOCAL_CFLAGS    += -fexceptions
LOCAL_CFLAGS += -Wno-error=deprecated-declarations

LOCAL_ARM_MODE := arm


目录结构

 jni
 |
 +-- main.cpp
 +-- Android.mk <- main Android
 +-- Application.mk
 +-- cflags.mk
 |
 +--DevIL
    |
    +-- Android.mk <- the Android.mk for DevIL
    +-- cflags.mk
    +--DevIL <-Directory containing DevIL source code
    +--Libjpeg <-Directory containing code of specific  DevIL dependency
    +--...<-Directory containing code of specific DevIL dependency


编辑:

我注意到我没有添加Application.mk,因此没有添加Application.mk

Application.mk

APP_PLATFORM := android-19
APP_ABI := armeabi-v7a
APP_STL:=c++_static
APP_LDFLAGS := -Wl,--build-id
NDK_TOOLCHAIN_VERSION := 4.9
ROOT_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
NDK_MODULE_PATH := $(ROOT_DIR)

最佳答案

Google在https://developer.android.com/ndk/guides/android_mk.html处的文档不正确。变量名称是LOCAL_EXPORT_C_INCLUDE_DIRS,而不是LOCAL_EXPORT_C_INCLUDES

关于android - NDK,LOCAL_EXPORT_C_INCLUDES无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35894726/

10-09 01:32