Android Studio CMake针对所有构建变体构建一次 [英] Android Studio CMake build once for all build variants

查看:99
本文介绍了Android Studio CMake针对所有构建变体构建一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有C ++代码(JNI)的项目,并且有许多构建变体和组合。这些用于实现应用程序的不同品牌/风格(即颜色,样式,图标等)。

I have a project with C++ code (JNI) and lots of build variants and combinations. These are used to implement different brandings / flavors of the app (i.e. colors, styles, icons, ...).

例如,可能有n个客户的构建变体:

For example there could be build variants for n customers :


  • customerNDebug

  • customerNDebugproguard

  • customerNRelease

  • customerNDebug
  • customerNDebugproguard
  • customerNRelease.

无论如何,每种商品口味的C / C ++层都是相同的。

Anyway, the C/C++ layer is the same for each product flavor.

通常,Android Studio中的 CMake 会为每个构建变体编译C代码。如果您具有诸如 调试版本之类的生成变体,而生成的代码实际上有所不同,则这是有道理的。但是,对于我拥有的构建变体,编译后的输出始终是相同的。

Normally CMake in Android Studio compiles C code for every build variant. This makes sense if you have build variants like "debug" and "release" where the resulting code actually differs. However, for the build variants I have, the compiled output is always the same.

目前,C / C ++代码的编译是使用我们外部的工具完成的。项目,而我只想在Android Studio中使用 CMake 进行编译,以仅对C / C ++代码提供适当的IDE支持。因此,对我而言,一个构建就足够了。

At the moment the compilation of C/C++ code is done using an external tool in our project and I want to compile using CMake in Android Studio only for proper IDE support of C/C++ code. So for me a single build would suffice.

是否可以告诉Android Studio仅构建C / C ++代码一次,无论构建变体和样式如何?

Is it possible to tell Android Studio to build C/C++ code only once, no matter the build variants and flavors?

推荐答案

默认情况下,Android Studio IDE与CMake和Gradle一起将生成一系列名为的本机生成任务根据您的构建类型和风格,选择externalNative< BuildVariant>构建。如果您想扭曲此行为,请采取以下解决方法:

By default, Android Studio IDE together with CMake and Gradle will generate a series of native build tasks named with externalNative<BuildVariant>Build according to your build types and flavours. If you want to twist this behaviour, some workaround is as below:


  1. 创建一个仅构建您的本机代码的Android Studio模块项目,例如共享本地

  2. 让其余模块依赖于此项目。

对于此解决方案,您需要考虑以下几点:

For this solution, you need to consider below points:


  1. 将您的 .so 文件放入其他项目可以查看和链接的适当位置。

  2. 对于此<$,您只能包括 debug release 生成类型c $ c> shared-native 模块项目,以避免太多的重建。或者,您可以简单地让其他项目取决于发行版类型,以便仅一次构建。

  1. Put your .so files into a proper location that other projects can see and link with.
  2. You can only include debug and release build types for this shared-native module project to avoid too many times of re-build. Or you can simply to let your other projects depends on the release type so that it will be built only ONCE.

这篇关于Android Studio CMake针对所有构建变体构建一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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