如何在Android Studio 2.2预览版1中正确使用NDK-Build [英] How to properly use NDK-Build in Android Studio 2.2 Preview 1

查看:145
本文介绍了如何在Android Studio 2.2预览版1中正确使用NDK-Build的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android Studio 2.2预览版1 具有新的外部ndk构建功能,但是根据官方博客文章中显示的app/build.gradle片段,根本不清楚如何设置其他的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"
  } 
}

如果可能的话,由于更好的C ++代码编辑器和Android Studio中的调试集成,我建议迁移到CMake构建系统.您将在此处找到有关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预览版5中,您必须将cmakendkBuild组包装在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"
    } 
  }
}

似乎由于构建工具中的错误,在externalNativeBuild组下包装ndkBuild无效.

Edit 2: It seems that wrapping ndkBuild under externalNativeBuild group does not work because of a bug in build tools.

这篇关于如何在Android Studio 2.2预览版1中正确使用NDK-Build的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆