Skip to content

Debug flag is enabled for release build type. #243

Open
@piwinux

Description

@piwinux

Description

The toolchain file provided for CMake (found in build/cmake/android.toolchain.cmake) enables the debug flags -g in Release mode.

Excerpt of the toolchain file:

# Generic flags.
list(APPEND ANDROID_COMPILER_FLAGS
        -g
       ...)
# ...
# Debug and release flags.
list(APPEND ANDROID_COMPILER_FLAGS_DEBUG
        -O0)

It seems that the -g should be set for ANDROID_COMPILER_FLAGS_DEBUG, not ANDROID_COMPILER_FLAGS.

A workaround is to set CMAKE_CXX_FLAGS_RELEASE to -g0 when configuring the build directory.

Environment Details

Not all of these will be relevant to every bug, but please provide as much
information as you can.

  • NDK Version: Pkg.Revision = 13.0.3315539
  • Build sytem: CMake
  • Host OS: Linux Debian Jessie
  • Compiler: Clang
  • ABI: arm64-v8a

Activity

DanAlbert

DanAlbert commented on Nov 29, 2016

@DanAlbert
Member

I'm guessing this was done for the same reason we do this in ndk-build: we always build a debugable binary but strip the debug info for the APK. I've sent an email to the Studio folks to find out if this is something that we can just fix, or if that's going to break Studio's debugging features (I don't know if they actually use Debug/Release modes).

DanAlbert

DanAlbert commented on Nov 29, 2016

@DanAlbert
Member

Yeah, sounds like Studio is expecting this. If you're using cmake via gradle, gradle will strip the debug info when you package the app. If you're not using gradle, you'll need to add that logic to your packaging tools.

DanAlbert

DanAlbert commented on Nov 29, 2016

@DanAlbert
Member

Closed for now, but if there's enough demand for this (I assume the case here is people using cmake and custom packaging tools rather than gradle), it should probably be re-opened and we can look in to getting Studio to do something different.

piwinux

piwinux commented on Dec 1, 2016

@piwinux
Author

Thanks for the reply! I understand that Studio is expecting compilation with debug flags even in release mode, but this is counter-intuitive in general, and goes against the default behavior one expects when using CMake in particular. This is actually why I filed this bug.

By default, CMake provides four build types: Debug, MinSizeRel, Release, and RelWithDebInfo. The behavior you describe (a release crafted with debug information) pertains with the RelWithDebInfo build type. I understand the specific needs for Studio, and I definitely understand the need/desires to change the default flags set by CMake, but I believe that the build flags set by the toolchain file should be aligned with the meaning of the build type.

If you're not using gradle, you'll need to add that logic to your packaging tools.

The Gradle behavior (stripping the debug symbols afterward) is a specific case, as is how Studio uses CMake. I fail to understand why I would need to do extra work to address a behavior that should not even happen when compiling a release.

DanAlbert

DanAlbert commented on Dec 2, 2016

@DanAlbert
Member

I've followed up on the email I sent earlier. All makes sense to me, but unfortunately it isn't my decision.

DanAlbert

DanAlbert commented on Dec 2, 2016

@DanAlbert
Member

Alright, looks like Studio is going to start using RelWithDebInfo in a future release (I think it's too late for 2.3 at this point). They've opened a bug for their side of things: https://code.google.com/p/android/issues/detail?id=229391

Reopening this for tracking the toolchain file fix. I think we can't actually change anything until their fix lands or we'll end up breaking their debugging, so this is going in the unplanned bucket for now.

added this to the unplanned milestone on Dec 2, 2016
piwinux

piwinux commented on Dec 5, 2016

@piwinux
Author

Hi, thanks a lot for the feedback. Nice to know it will be considered.

tallytalwar

tallytalwar commented on Feb 8, 2017

@tallytalwar

Perfect.

On our project, we recently moved to native build setup via gradle using externalnativebuild and cmake and noticed bloated native library sizes in our aar's. But the final apk had stripped out minified native library.

In full agreement with the description of the issue here, and appreciate the android studio team considering the request. 👍

26 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @baryluk@DanAlbert@tallytalwar@ericoporto@piwinux

        Issue actions

          Debug flag is enabled for release build type. · Issue #243 · android/ndk