34

I'm getting sigsegv 11 in native code and i need to avoid stripping to understand what's wrong. The app uses library (aar) and i was able to avoid stripping for the aar with 'cmd-strip' hack. But in the apk stripped version of .so is used anyway so the app strips the symbols, probably while transformNative_libsWithStripDebugSymbolForDebug gradle task. Any change to avoid it?

PS. Found similar question on SO but it's a bit different (using aar here with not stripped symbols in my case).

Community
  • 1
  • 1
4ntoine
  • 19,816
  • 21
  • 96
  • 220
  • IMO, you should think twice if you really need to ship non-stripped binaries with your APK. Cons are extremely increased size of shared libraries and poor reverse engineering protection. If you just want to find non-stripped binaries somewhere - look under `obj/local/`. See [here](http://stackoverflow.com/a/40278937/2878070) for details. – Sergio Nov 01 '16 at 09:52
  • 2
    it's just to fix the issue, not for distribution – 4ntoine Nov 01 '16 at 13:10
  • If so - `ndk-build` creates non-stripped files along with stripped ones already. See my previous comment. – Sergio Nov 01 '16 at 13:22
  • they are not stripped when building aar, but ARE stripped when building app. see my question – 4ntoine Nov 01 '16 at 13:56

2 Answers2

58

There's an undocumented method 'doNotStrip' in packagingOptions, just add following lines in your build.gradle

packagingOptions{
    doNotStrip "*/armeabi/*.so"
    doNotStrip "*/armeabi-v7a/*.so"
    doNotStrip "*/x86/*.so"
}
Wayne Cai
  • 768
  • 6
  • 3
  • 1
    You shouldn't do this. It will make your APK huge and it's unnecessary. See my answer on how to symbolize your stack traces. – Dan Albert Apr 26 '17 at 18:42
  • 3
    it's needed only because some .so files are encrypted and would be broken if stripped. – Wayne Cai Jun 16 '17 at 08:57
  • fwiw, i'm having the exact opposite issue with Android Studio 3.1/3.2 and gradle 4.4. It no longer strips debug symbols and I can't find a way to force stripping! not LOL. – 3c71 Feb 02 '18 at 20:00
  • @3c71: That's a bug that was fixed in 3.2 canary 4: https://issuetracker.google.com/72752164 – Dan Albert Feb 26 '18 at 21:39
  • 1
    @DanAlbert I actually opened that issue ;) – 3c71 Feb 28 '18 at 19:01
  • Heh, didn't notice the date. Thanks for reporting the issue! – Dan Albert Feb 28 '18 at 22:08
  • You are amazing! This also fix the same issue using NDK 17. – Lucas Lima May 16 '18 at 20:01
  • 3
    Well, this **is** required when profiling app with simpleperf, as described [here](https://android.googlesource.com/platform/prebuilts/simpleperf/+/ndk-r14-beta1/README.md), because without this symbols are missing in profile report. Also, when using Android Studio's native profiler, it does not display symbols **even** if native libraries are not stripped, meaning that it does not use the `simpleperf` internally... – DoDo Aug 22 '18 at 17:32
  • What's the equivalent of doNotStrip in Apache Ant? – Sixjac Mar 25 '22 at 14:14
8

Fortunately you don't actually need to keep the symbols in the app. The NDK ships a tool called ndk-stack (it's in the root of the NDK) that can symbolize a stack trace for you: https://developer.android.com/ndk/guides/ndk-stack.html

Dan Albert
  • 10,079
  • 2
  • 36
  • 79
  • 1
    It seems doNotStrip is needed to see symbols in logcat in case of crash, and to perform debuging with lldb in Android Studio – aberaud Nov 04 '19 at 20:17
  • 1
    The former is handled by ndk-stack, and the latter is not true. If you're seeing the latter it's a bug and you should file it. – Dan Albert Nov 05 '19 at 20:24
  • 3
    We couldn't find a way to use any sort of debugging with lldb without doNotStrip. No symbol names in the debug stack, no local variable names, no breakpoints etc (with NDK 21 and Android Studio beta). Where to report a bug (NDK or Android Studio) ? Also using ndk-stack is very cumbersome compared to simply seeing the backtrace in the logcat. Maybe Android Studio can automate this ? Thanks – aberaud Nov 05 '19 at 21:02
  • It would be an Android Studio bug. Follow https://source.android.com/setup/contribute/report-bugs – Dan Albert Nov 06 '19 at 21:18
  • "Also using ndk-stack is very cumbersome compared to simply seeing the backtrace in the logcat. Maybe Android Studio can automate this ?" Yeah, that would be good. If you file the FR I can help find an owner for it. – Dan Albert Nov 06 '19 at 21:19
  • Created https://issuetracker.google.com/issues/144151370 and https://issuetracker.google.com/issues/144150380 – aberaud Nov 08 '19 at 20:59