I need to define some custom macros such as "DEBUG", "RELEASE", "DEMO_VER" and "FULL_VER" in Android Studio build.gradle file so that my C/C++ code can detect them like:
#ifdef DEBUG
...
#else //RELEASE
...
#endifor
#ifdef DEMO_VER
...
#else //FULL_VER
...
#endifMy understanding is that these macros should be defined as g++ compiler options in the build variant blocks like the following code:
buildTypes
{
release
{
cmake <<====== Error!!!!!: could not find method cmake() for ...BuildType
{
cppFlags += "-DRELEASE"
}
}
debug
{
cmake <<====== Error!!!!!: could not find method cmake() for ...BuildType
{
cppFlags += "-DDEBUG"
}
}
}
flavorDimensions "version"
productFlavors
{
demo
{
cmake <<====== Error!!!!!: could not find method cmake() for ...ProductFlavor
{
cppFlags += "-DEMO_VER"
}
}
full
{
cmake <<====== Error!!!!!: could not find method cmake() for ...ProductFlavor
{
cppFlags += "-DFULL_VER"
}
}
}The problem is that I can not use "cmake" inside either "BuildType" nor "ProductFlavor", the method can not be found. So what is the correct way to pass in compiler macros for different product flavors / build types?
full { externalNativeBuild {
cmake {
cppFlags += "-DFULL_VER"
}