title: Android NDK UnsatisfiedLinkError: "dlopen failed: empty/missing DT_HASH"
body: <p>I am tracking down crashes with our Android application (which uses the NDK to load a custom C++ library) using a crash reporting service. A small number of users are experiencing the following crash:</p>
  <pre><code>java.lang.UnsatisfiedLinkError: dlopen failed: empty/missing DT_HASH in &quot;cpplibrary.so&quot; (built with --hash-style=gnu?)
     at java.lang.Runtime.loadLibrary(Runtime.java:365)
     at java.lang.System.loadLibrary(System.java:526)
  </code></pre>
  <p>The couple of mentions of this error I can find on the internet (for example this <a href="https://groups.google.com/forum/#!topic/Android-ndk/4-_PpwySQIo" rel="nofollow noreferrer">Google Groups post</a>) discuss problems with building the libs, which cause this error to occur every time the app is run.  There is little information on why this might happen sporadically.  <a href="https://stackoverflow.com/questions/10645249/intermittent-android-ndk-unsatisfiedlinkerror">This post</a> is the closest I can find.</p>
  <p>Based on the crash traces, it looks like any particular user will experience this constantly for stretches; I am not sure if these users are ever able to load the lib correctly. Does anyone have ideas on what might cause this to happen only sometimes? Can I do the NDK build differently to try and stop it?</p>
  <p>Thanks!</p>
  <p>Edit: <a href="https://stackoverflow.com/questions/17818058/android-ndk-unsatisfiedlinkerror-a-surprising-reason">This post</a> mentions two ways to get such errors conditionally; I will be looking in to them.</p>
  <p>Edit2: Build files:
  Android.mk (excerpt):</p>
  <pre><code>include $(CLEAR_VARS)
  LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
  LOCAL_C_INCLUDES := &lt;Source Path&gt;...
  LOCAL_CFLAGS := -DANDROID -Wall
  LOCAL_CPPFLAGS := -DENABLE_SDK_DEBUGGING=1 -DENABLE_SDK_LOGGING=1
  LOCAL_MODULE := cpplibrary
  LOCAL_SRC_FILES := &lt;Source Files&gt; / ...
  
  LOCAL_LDLIBS    := -llog -landroid
  LOCAL_STATIC_LIBRARIES := cpplibrary
  include $(BUILD_SHARED_LIBRARY)
  </code></pre>
  <p>Application.mk:</p>
  <pre><code>APP_STL := stlport_static
  APP_CFLAGS += -std=c++11
  </code></pre>