[英]How to set cpp folder for a specific build flavor
I have an issue with adding a cpp
folder and CMakelist.txt
file to a specific flavor in android studio. 我有一个问题,将
cpp
文件夹和CMakelist.txt
文件添加到android studio中的特定风格。
I was working on three separate apps with a unique database structure, so I tried to make these three apps as one application using build flavors and other related settings. 我正在研究具有独特数据库结构的三个独立应用程序,因此我尝试使用构建风格和其他相关设置将这三个应用程序作为一个应用程序。
For the first two apps, it did so well, but for the last one, I faced an issue that I had no idea how to add cpp
folder and CMakelist.txt
file to that specific flavor using Gradle. 对于前两个应用程序,它做得很好,但对于最后一个,我遇到了一个问题,我不知道如何使用Gradle将
cpp
文件夹和CMakelist.txt
文件添加到该特定风格。 As you may have guessed, the last application is NDK based and uses a CMakelist.txt
file and has an activity that works with JNI. 您可能已经猜到,最后一个应用程序是基于NDK的,并使用
CMakelist.txt
文件并具有与JNI一起使用的活动。
android {
...
defaultConfig {
applicationId "com.example"
...
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
flavorDimensions 'program'
productFlavors {
first {
dimension = 'program'
applicationIdSuffix = '.first'
}
second {
dimension = 'program'
applicationIdSuffix = '.second'
}
third {
dimension = 'program'
applicationIdSuffix = '.third'
externalNativeBuild {
cmake {
relativeProjectPath "src/third/cpp/CMakeLists.txt"
version "3.10.2"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
ndk { abiFilters "arm64-v8a" }
}
debug {
ndk { abiFilters "arm64-v8a" }
}
}
}
}
I am using a relativeProjectPath
method in gradle, and expect that CMakelist.txt
links with my cpp
folders but nothing happens. 我在gradle中使用
relativeProjectPath
方法,并期望CMakelist.txt
链接到我的cpp
文件夹,但没有任何反应。
I have not tried it that way. 我没有那样试过。 What worked for me in my previous projects is this.
在我以前的项目中对我有用的是这个。
android {
...
flavorDimensions "program"
productFlavors {
...
third {
dimension "program"
externalNativeBuild.cmake {
arguments "-DFLAVOR=THIRD_PROGRAM"
}
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
...
}
Then in your CMakeList.txt
, do this conditional test 然后在您的
CMakeList.txt
,执行此条件测试
if(${FLAVOR} STREQUAL "THIRD_PROGRAM")
// build your cpp codes for flavor THIRD
else()
// nothing to build?
endif()
Note that my CMakeList.txt
is in app/
directory. 请注意,我的
CMakeList.txt
位于app/
目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.