Discussion:
Android Studio / NDK: How to define custom macros in build.gradle (for different build variants) and let native C/C++ code detect them?
Toothy Bunny
2018-10-17 19:01:22 UTC
Permalink
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
...#endif

or

#ifdef DEMO_VER
...#else //FULL_VER
...#endif


My 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?
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/85fe50c2-8654-406a-a5d3-5cdb97729c38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Kostiantyn.Zghirovskyi via android-ndk
2018-10-17 20:19:30 UTC
Permalink
You forgot to declare externalNativeBuild block

full {

externalNativeBuild {
cmake {
cppFlags += "-DFULL_VER"
}

}}
Post by Toothy Bunny
I need to define some custom macros such as "*DEBUG*", "*RELEASE*", "
*DEMO_VER*" and "*FULL_VER*" in Android Studio *build.gradle* file so
#ifdef DEBUG
...#else //RELEASE
...#endif
or
#ifdef DEMO_VER
...#else //FULL_VER
...#endif
My understanding is that these macros should be defined as g++ compiler
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?
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/58864bf6-5f50-499c-a55e-b6f6856a672a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...