Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
839 views
in Technique[技术] by (71.8m points)

android - How to use ndk-stack with shared library in AAR file

I'm using shared object libraries in Android application. These shared object libraries are in .aar file.

One of library is crashing. In order to check crash logs and exact line no. I am using ndk-stack took.

Usage of ndk-stack is

$ adb logcat |  ndk-stack -sym <Path to  your shared libraries>

Now How can I get a path of shared libraries in AAR file?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should keep in mind that not every .so file is useful for ndk-stack. Android NDK produces two kinds of .so files: stripped and non-stripped. The most difference is that last ones contain debug information, that is needed for ndk-stack and first ones don't. readelf may help to check if particular file is stripped or not:

$ readelf <non-stripped-lib> -S | grep debug
  [23] .debug_info       PROGBITS        00000000 00302c 0052d9 00      0   0  1
  [24] .debug_abbrev     PROGBITS        00000000 008305 000879 00      0   0  1
  [25] .debug_loc        PROGBITS        00000000 008b7e 001aa7 00      0   0  1
  [26] .debug_aranges    PROGBITS        00000000 00a628 000088 00      0   0  8
  [27] .debug_ranges     PROGBITS        00000000 00a6b0 0000d0 00      0   0  1
  [28] .debug_line       PROGBITS        00000000 00a780 0009de 00      0   0  1
  [29] .debug_str        PROGBITS        00000000 00b15e 002387 01  MS  0   0  1
  [30] .debug_frame      PROGBITS        00000000 00d4e8 0003d0 00      0   0  4
$

$ readelf <stripped-lib> -S | grep debug
$ 

As you see not-stripped ELF has a lot of .debug_* sections, that indeed contain line numbers, private / static function names, etc.

Next, .aar files, both debug and release ones, has only stripped binaries. So they are useless for ndk-stack.

AFAIK, the only place where non-stripped binaries may be found is a obj/ dir. Its location depends slightly on used build system:

  • for ndk-build it is under <module_name>/build/intermediates/ndk
  • for CMake-based it is under <module_name>/build/intermediates/cmake

Also it looks like out-of-the-box android gradle plugin offers no way to pack unstripped libraries to your aar, so the only way here is some custom task in your build.gradle.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...