easiest way to debug crash in native library, linked by Android app?

前端 未结 5 1062
太阳男子
太阳男子 2021-02-06 00:53

I have ported and created several low-level C-libraries to Android for my use in my application. I cross-compiled them using the NDK, and then link to them using System.loadLib

5条回答
  •  醉梦人生
    2021-02-06 01:35

    If your application is truly crashing in native code, I highly recommend the following:

    1. Set a java breakpoint that will be hit after your native library has been loaded but before it starts executing.
    2. Go to the terminal and launch the ndk's version of gdb (it's called "ndk-gdb"). Initially, just type "c" to continue.
    3. Back in java, continue execution.
    4. Once your app crashes, gdb will pause and you can examine the integrity of the stack in native code via the "bt" command (backtrace).

    At any rate, you should be able to fully debug native code and catch problems via ndk-gdb. You can find specific documentation on the ndk's version of gdb in your local installation of the ndk (for example, on my machine it's here):

    android-ndk-r6/documentation.html

    Finally, here's a basic tutorial on gdb:

    gdb tutorial

    Hope this helps!

提交回复
热议问题