title: Android NDK UnsatisfiedLinkError when calling a native function that resides in an Android Library Project
body: <p>I built an android app that used the android NDK to make a shared native library (.so) to compute sha1's and it worked just fine when it was in one self contained project. Recently though I made that project into an Android Shared Project and kept the jni code there.. I then made a new project which references the shared project and the project seems to work correctly except that I get an UnsatisfiedLinkError when calling the native function.
  The native function gets called from within a Java Class named Hash. Inside this class there are some native functions that make calls to compute a sha1 hash for a file.</p>
  
  <p>The ndk/jni code is getting compiled and it does get into application's APK, however I continue to get that error. I've uninstalled the app on my phone, done an ndk-build clean to make sure its not getting old references.. Etc and no luck. I've also made sure that the names of my jni functions match the </p>
  
  <p>So here is the gist of my code:</p>
  
  <p><strong>Hash.java</strong></p>
  
  <pre><code>package com.mydomain.sdk.util.Hash
  
  public class Hash {
      static {
        System.loadLibrary("native_sha1")
      }
  
      public static native String getFileHashNative(String fileName);
  
  }
  </code></pre>
  
  <p>Then I have (in the same project</p>
  
  <p><strong>jni/Android.mk</strong></p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
  LOCAL_LDLIBS := -llog
  LOCAL_MODULE    := native_sha1
  LOCAL_SRC_FILES := sha1.c sha1_native.c
  include $(BUILD_SHARED_LIBRARY)
  </code></pre>
  
  <p><strong>jni/sha1_native.c</strong></p>
  
  <pre><code>jstring Java_com_mydomain_sdk_util_Hash_getFileHashNative(JNIEnv * env, jclass this, jstring fileName)
  {
    //call function from sha1.c to get sha1, return to user
  }
  </code></pre>
  
  <p>Anyways, this all worked great until I changed the structure of my project so that I could reuse common code (putting this into the android library project). If I compile my app and open up the .apk file I can see a lib directory and within that there is armeabi/libnative_sha1.so file.. Thus, it definitely is in there its just not working.</p>
  
  <p><strong>Update - Some Debug Information</strong></p>
  
  <p>Ok so I added some debugging.. I took the loadLibrary out of a static block and put it in a function which I call before attempting to call Hash.getFileHashNative</p>
  
  <pre><code>12-15 12:34:13.143: D/Hash(31567): Attempting to load native_sha1 lib
  12-15 12:34:13.153: D/dalvikvm(31567): Trying to load lib /data/data/com.mydomain/lib/libnative_sha1.so 0x4051e4f8
  12-15 12:34:13.163: D/dalvikvm(31567): Added shared lib /data/data/com.mydomain/lib/libnative_sha1.so 0x4051e4f8
  
  12-15 12:34:13.163: D/dalvikvm(31567): No JNI_OnLoad found in /data/data/com.mydomain/lib/libnative_sha1.so 0x4051e4f8, skipping init
  12-15 12:34:13.163: W/dalvikvm(31567): No implementation found for native Lcom/mydomain/sdk/util/Hash;.getFileHashNative (Ljava/lang/String;)Ljava/lang/String;
  </code></pre>
  
  <p>I'm not sure what is causing this but it appears it can't find the function obviously..
  The only thing I'm modifying is the name of mydomain, everything else is exact..
  Also note that my library project has the package name of com.mydomain.sdk and my application project is just com.mydomain
  The source code for the sha1 resides in the library project under com.mydomain.sdk.util.Hash
  I don't get what is going on here. Any ideas?</p>