且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android Studio CMake 为所有构建变体构建一次

更新时间:2023-09-26 10:53:58

默认情况下,Android Studio IDE 与 CMake 和 Gradle 一起会生成一系列以 externalNativeBuild 命名的原生构建任务根据您的构建类型和风格.如果你想扭转这种行为,一些解决方法如下:

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. 您只能为此shared-native 模块项目包含debugrelease 构建类型,以避免多次重新构建.或者您可以简单地让您的其他项目依赖于发布类型,以便它只构建ONCE.
  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.