-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debug flag is enabled for release build type. #243
Comments
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). |
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. |
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. |
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:
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. |
I've followed up on the email I sent earlier. All makes sense to me, but unfortunately it isn't my decision. |
Alright, looks like Studio is going to start using 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. |
Hi, thanks a lot for the feedback. Nice to know it will be considered. |
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. 👍 |
- to disable `-g` debug flag being set by the ndk default android cmake toolchain - Refer: android/ndk#243 TODO: Keep an eye for future versions of ndk/android-studio to add a fix for this
- to disable `-g` debug flag being set by the ndk default android cmake toolchain - Refer: android/ndk#243 TODO: Keep an eye for future versions of ndk/android-studio to add a fix for this
- to disable `-g` debug flag being set by the ndk default android cmake toolchain - Refer: android/ndk#243 TODO: Keep an eye for future versions of ndk/android-studio to add a fix for this
This dramatically reduces the size of the archives and binaries. For some reason the android.toolchain.cmake file provided by Android NDK adds -g to the compiler flags, even when building in Release mode (the default). A new build mode RelWithDebInfo has been added to the patched android.toolchain.cmake file, which matches the standard behavior of the Android NDK. There is an open issue at android/ndk#243 that describes the rationale.
I am amazed that this is still an open issue 3 years later. Can we get this fixed please, it doesn't sound very difficult if Android Studio is now using |
no, the problem is that Studio currently requires this. that's bug https://code.google.com/p/android/issues/detail?id=229391 and until/unless that's fixed, there's nothing we can do in the NDK. |
This is not a bug IMHO, and working as intended, so should be closed. Release version has nothing to do whatever debug symbols are present or not. If you really want to change this behavior just set |
Turn off some optimizations:
Breaking expected behavior, we think it's if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(C_FLAGS "${C_FLAGS} -Os -fvisibility=hidden -fvisibility-inlines-hidden")
set(LINKER_FLAGS "${LINKER_FLAGS} -Wl,-exclude-libs,ALL -Wl,--gc-sections -Wl,--strip-all")
else ()
set(C_FLAGS "${C_FLAGS} -O0")
endif () |
Looks like https://issuetracker.google.com/37128614 was fixed so now we need to wait for that version of AGP to release and decide on a compatibility window (whatever NDK we change this in will be incompatible with all current AGP versions). |
I expect when AGP does a |
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:
It seems that the
-g
should be set forANDROID_COMPILER_FLAGS_DEBUG
, notANDROID_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.
The text was updated successfully, but these errors were encountered: