NDK Programmer's Guide
ndk-depends Tool

Introduction

The ndk-depends tool that comes with this Android NDK allows you to dump the ELF dependencies of a given ELF shared library or executable.

With the –print-java option, it can also be used to generate a Java source fragment to load your native library and its dependencies in the correct order (see example below).

Use 'ndk-depends --help' for complete usage information.

This tool is designed to support:

  • Either 32-bit or 64-bit ELF binaries.
  • Either little-endian or big-endian ELF binaries.
  • Unicode file paths, on Windows.

Note: The Windows binary will NOT work with Cygwin paths !

Examples

  • ndk-depends path/to/libfoo.so Dump all dependencies of libfoo.so, in topological order, so that any library listed in the result appears before any other library it depends on.
  • ndk-depends --print-paths path/to/libfoo.so Same as above, but also prints the path of the libraries on your host file system.
  • ndk-depends -L some/other/path path/to/libfoo.so Append 'some/other/path' to the search path for depending libraries when looking at the dependencies for 'libfoo.so'
  • ndk-depends --print-direct path/to/libfoo.so Only print the direct dependencies of libfoo.so, and nothing else, in the order they appear in the file.
  • ndk-depends path/to/libfoo.so --print-java Prints a Java source fragment that corresponds to the load of 'libfoo' with System.loadLibrary(). This lists all libraries in reverse order, and ignores system libraries (e.g. libc.so).
  • ndk-depends path/to/libfoo.so --print-dot | dot -Tpng -o /tmp/graph.png Prints the dependency graph as Graphviz .dot file, then generate a PNG image for it.
  • ndk-depends --help Print complete usage details.

Let's assume your project has the several libraries:

    libfoo.so -> depends on libbar.so and libzoo.so
    libbar.so -> depends on the system's liblog.so
    libzoo.so -> depends on libbar.so

Then 'ndk-depends libs/armeabi/libfoo.so' will typically print:

    libfoo.so
    libzoo.so
    libbar.so
    liblog.so

And 'ndk-depends --print-java libs/armeabi/libfoo.so' will print:

    System.loadLibrary("bar");
    System.loadLibrary("zoo");
    System.loadLibrary("foo");

This is handy to avoid computing the reverse library order yourself for complex projects.

For more details, see the output of 'ndk-depends --help'.