如何在 Android Studio 2.2 Preview 1 中正确使用 NDK-Build [英] How to properly use NDK-Build in Android Studio 2.2 Preview 1
问题描述
Android Studio 2.2 Preview 1 有一个新的外部 ndk 构建功能,但是从官方博客文章中显示的 app/build.gradle
片段来看,完全不清楚如何设置 Application.mk
文件通常包含的其他 ndk 构建参数
Android Studio 2.2 Preview 1 has a new external ndk build feature, but from app/build.gradle
snippet shown in official blog post it's not clear at all how to set additional ndk build parameters which Application.mk
file usually contains
我可以通过 externalNativeBuild
设置 Android.mk
ndk 构建文件,但是如何设置所需的 Application.mk
变量?
I'm able to set Android.mk
ndk build file via externalNativeBuild
, but how could I set the required Application.mk
variables?
我的 Application.mk
包含:
NDK_TOOLCHAIN_VERSION := clang
APP_PLATFORM := android-16
APP_ABI := armeabi
APP_STL := c++_static
APP_CPPFLAGS += -std=c++11
推荐答案
带有更新的 gradle 插件的 Android Studio 2.2 Preview 3 添加了对其他参数的支持.您可以像这样设置 Application.mk 和其他配置:
Android Studio 2.2 Preview 3 with updated gradle plugin added support for additional arguments. You can set Application.mk and additional configuration like this:
defaultConfig {
ndkBuild {
arguments "NDK_APPLICATION_MK:=Application.mk"
cFlags "-DTEST_C_FLAG1" "-DTEST_C_FLAG2"
cppFlags "-DTEST_CPP_FLAG2" "-DTEST_CPP_FLAG2"
abiFilters "armeabi-v7a", "armeabi"
}
}
如果可能,我会建议迁移到 CMake 构建系统,因为 Android Studio 中有更好的 C++ 代码编辑器和调试集成.您将在此处找到有关 gradle 插件配置的更多信息:https://sites.google.com/a/android.com/tools/tech-docs/external-c-builds.
If possible I would recommend migrating to CMake build system, because of better C++ code editor and debugging integration in Android Studio. You will find more info on gradle plugin configuration here: https://sites.google.com/a/android.com/tools/tech-docs/external-c-builds.
从 Android Studio 2.2 Preview 5 开始,您必须将 cmake
和 ndkBuild
组包装在 externalNativeBuild
组下:
From Android Studio 2.2 Preview 5 you must wrap cmake
and ndkBuild
groups under externalNativeBuild
group:
defaultConfig {
externalNativeBuild {
ndkBuild {
targets "target1", "target2"
arguments "NDK_APPLICATION_MK:=Application.mk"
cFlags "-DTEST_C_FLAG1", "-DTEST_C_FLAG2"
cppFlags "-DTEST_CPP_FLAG2", "-DTEST_CPP_FLAG2"
abiFilters "armeabi-v7a", "armeabi"
}
}
}
编辑 2: 似乎由于构建工具中的错误,将 ndkBuild
包装在 externalNativeBuild
组下不起作用.
Edit 2: It seems that wrapping ndkBuild
under externalNativeBuild
group does not work because of a bug in build tools.
这篇关于如何在 Android Studio 2.2 Preview 1 中正确使用 NDK-Build的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!