How to build an apk in in release mode from Android-Studio?

I’m trying to build an apk in release mode as I have few places in code with debug guards that I don’t want in release build.

#if COCOS2D_DEBUG
    // something for debug only...
#endif

From terminal I invoke: cocos compile -p android -m release --android-studio (compiles successfully)
but still resulted apk has debug code in it…

What am I doing wrong?

I would also like to know how to run a release apk from Android studio

cocos2dx team made a great progress on gradle for Android studio in 3.15.1. I tried some options till I found, how to get the new gradle building system in Android studio up and ready for my old 3.11 project:

Migration:
I had a 3.11, so I updated all directories (copy/paste of cocos2d directory) and wanted to use the new gradle, so:

  1. I created a new cocos2dx project
    cocos new newProject -p xx.company.area.Project -l cpp -d /Users/xxx/Development/temp
    where newProject is exactly the same project name as the old one, also package name is the same - but stored in a temp directory
  2. tar-ed the proj.android-studio to not miss hidden (starting with “.”) files:
    cd newProject/proj-android-studio
    tar cvfz content.tar.gz . -----> use “.” not “*” !!!
    cd oldProject/proj.android-studio
    rm -rf *
    mv newProject/proj.android-studio/content.tar.gz oldProject/proj.android-studio/
    cd oldProject/proj.android-studio/
    tar xvfz content.tar.gz
  3. edit oldProject/.cocos-project.json, where I set 3.15.1 as a version

Configuration:
After opening of a project in Android studio:

  1. Build => Edit build types => Signing
    I entered data to the signing certificate
  2. Build => Edit build types => Build Types
    I selected “release” for Signing Config
  3. Build => Build variants
    I changed “debug” to “release”
  4. Run/build your project and the APK file will be created in
    /oldProject/proj.android-studio/app/build/outputs/apk/oldProject-release.apk

If your project is in GIT, you will see changes in some IDEA files and in /oldProject/proj.android-studio/app/build.gradle

That’s it, for me everything is working out of Android studio…

PS:
At first I tried using

  1. cocos compile -p android -m release --android-studio
  2. entering data of certificate (stored then in /oldProject/proj.android-studio/app/gradle.properties
    but build from a console and from Android studio worked differently for me, so now I work in Android studio only