Debugging Your Project

Debugging native crashes

If you're struggling to understand a native crash dump or tombstone, Debugging Native Android Platform Code is a good introduction.

For a fuller catalog of common types of crash and how to investigate them, see Diagnosing Native Crashes.

The ndk-stack tool can help symbolize your crashes, and ndk-gdb lets you attach gdb from the command-line, though you're probably better off using Android Studio's built-in lldb support described in their general Debug your app documentation.

Debugging native memory issues

Malloc debug

See Malloc Debug and Native Memory Tracking using libc Callbacks for a thorough description of the C library's built-in options for debugging native memory issues.

Address Sanitizer (ASan)

Since Android 8.0 (Oreo) it's also possible to use ASan to debug apps on non-rooted production devices. This is similar to Valgrind, but significantly faster and much better supported. You can find detailed instructions on the ASan wiki.

Malloc hooks

If you want to build your own tools, Android's libc also supports intercepting all allocation/free calls that happen during program execution. See the malloc_hooks documentation for usage instructions.

Malloc statistics

Android supports the mallinfo(3) and malloc_info(3) extensions to <malloc.h>.

The malloc_info functionality is available in Android 6.0 (Marshmallow) and higher and its XML schema is documented in Bionic's malloc.h header.


For CPU profiling of native code, you can use Simpleperf.