使用ndk-build的Android Studio本机lib构建错误

时间:2018-05-06 18:23:17

标签: android-studio android-ndk ndk-build

我想用Android Studio构建c / c ++代码,而不是手动使用ndk-build脚本(到目前为止,我一直使用Android.mk和Application.mk以及ndk-build脚本来构建.so库)。我正在尝试配置项目。在我的build.gradle中,我有以下几行:

externalNativeBuild {
        ndkBuild {
            path 'src/main/jni/Android.mk'
        }
    }

在目录src / main / jni下面有Application.mk文件和所有C / C ++源代码:

jni/
 -jpeg8d-master/   (a directory)
 -other directories..
 -android.mk
 -application.mk
 -common.h
 -other .c/.cpp/.h files

文件common.h指的是(本地)目录jpeg8d-master /下的文件jpeglib.h。以旧方式(在jni /文件夹下运行ndk-build),一切正常。当我尝试使用Android Studio制作项目(Ctrl-F9)时,在Build选项卡上我看到以下错误:

Build command failed.
Error while executing process D:\android\android-ndk-r16b\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\android\android-studio-workspace\MyAPP\app\src\main\jni\Android.mk NDK_APPLICATION_MK=C:\android\android-studio-workspace\MyApp\app\src\main\jni\Application.mk APP_ABI=x86_64 NDK_ALL_ABIS=x86_64 NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=C:/android/android-studio-workspace/MyApp/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=C:\android\android-studio-workspace\MyApp\app\build\intermediates\ndkBuild\debug\lib C:/android/android-studio-workspace/MyApp/app/build/intermediates/ndkBuild/debug/obj/local/x86_64/libnative.so}
[x86_64] Compile++      : native <= wrapper.cpp
In file included from C:/android/android-studio-workspace/MyApp/app/src/main/jni/wrapper.cpp:29:
C:/android/android-studio-workspace/MyApp/app/src/main/jni/common.h:31:10: warning: non-portable path to file '"eigen/Eigen/Dense"'; specified path differs in case from file name on disk [-Wnonportable-include-path]
#include "eigen/eigen/Dense"
         ^~~~~~~~~~~~~~~~~~~
         "eigen/Eigen/Dense"
C:/android/android-studio-workspace/MyApp/app/src/main/jni/common.h:209:10: fatal error: 'jpeglib.h' file not found
#include        "jpeglib.h"
                ^~~~~~~~~~~
1 warning and 1 error generated.
make: *** [C:/android/android-studio-workspace/MyApp/app/build/intermediates/ndkBuild/debug/obj/local/x86_64/objs/native/wrapper.o] Error 1

可能没有从jni /目录中调用ndk-build命令,或者缺少其他东西。有什么帮助吗?

1 个答案:

答案 0 :(得分:2)

你是对的,Android Studio运行ndk-build时的当前目录是app目录(你有 build.gradle 文件,在你的情况下是C:/android/android-studio-workspace/MyApp/app)。 / p>

您应该修复 Android.mk 以包含相对于 LOCAL_PATH 的所有包含路径,例如

LOCAL_C_INCLUDES += $(LOCAL_PATH)/eigen

等等。