Android 使用 ndk-build 的 Studio 本机库构建错误
Android Studio native lib build error using 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。以旧方式(运行 ndk-build 在 jni/ 文件夹下),一切正常。当我尝试使用 Android Studio 制作项目 (Ctrl-F9) 时,在“构建”选项卡上我看到以下错误:
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 命令,或者缺少其他内容。有帮助吗?
你是对的,Android Studio运行ndk-build时的当前目录是app目录(你有build.gradle文件,在你的情况是 C:/android/android-studio-workspace/MyApp/app
).
您应该修复 Android.mk 以包含所有相对于 LOCAL_PATH 的路径,例如
LOCAL_C_INCLUDES += $(LOCAL_PATH)/eigen
等等。
我想用 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。以旧方式(运行 ndk-build 在 jni/ 文件夹下),一切正常。当我尝试使用 Android Studio 制作项目 (Ctrl-F9) 时,在“构建”选项卡上我看到以下错误:
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 命令,或者缺少其他内容。有帮助吗?
你是对的,Android Studio运行ndk-build时的当前目录是app目录(你有build.gradle文件,在你的情况是 C:/android/android-studio-workspace/MyApp/app
).
您应该修复 Android.mk 以包含所有相对于 LOCAL_PATH 的路径,例如
LOCAL_C_INCLUDES += $(LOCAL_PATH)/eigen
等等。