How to avoid stripping for native code symbols for android app
Asked Answered
B

3

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).

Balderdash answered 1/11, 2016 at 6:38 Comment(4)
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 for details.Quid
it's just to fix the issue, not for distributionBalderdash
If so - ndk-build creates non-stripped files along with stripped ones already. See my previous comment.Quid
they are not stripped when building aar, but ARE stripped when building app. see my questionBalderdash
S
58

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

packagingOptions {
    doNotStrip "*/arm64-v8a/*.so"
    doNotStrip "*/armeabi-v7a/*.so"
    doNotStrip "*/x86/*.so"
    doNotStrip "*/x86_64/*.so"
}
Stent answered 16/2, 2017 at 8:53 Comment(9)
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.Fictionalize
it's needed only because some .so files are encrypted and would be broken if stripped.Stent
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.Accuracy
@3c71: That's a bug that was fixed in 3.2 canary 4: issuetracker.google.com/72752164Fictionalize
@DanAlbert I actually opened that issue ;)Accuracy
Heh, didn't notice the date. Thanks for reporting the issue!Fictionalize
You are amazing! This also fix the same issue using NDK 17.Jacynth
Well, this is required when profiling app with simpleperf, as described here, 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...Polychromatic
What's the equivalent of doNotStrip in Apache Ant?Flatfoot
F
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

Fictionalize answered 1/11, 2016 at 20:29 Comment(6)
It seems doNotStrip is needed to see symbols in logcat in case of crash, and to perform debuging with lldb in Android StudioCavalierly
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.Fictionalize
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 ? ThanksCavalierly
It would be an Android Studio bug. Follow source.android.com/setup/contribute/report-bugsFictionalize
"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.Fictionalize
Created issuetracker.google.com/issues/144151370 and issuetracker.google.com/issues/144150380Cavalierly
S
1

In gradle 8.7, AGP 8.3.2, it should be

android {
    buildTypes {
        release {
            ...
        }
        debug {
            ...
            packaging {
                jniLibs {
                    keepDebugSymbols += "**/*.so"
                }
            }
        }
    }
}
Scallion answered 14/5 at 14:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.