title: Android NDK cmake JNI static library
body: <p>Because of security concerns I would like to link all libraries statically including my native library containing JNI_OnLoad function. I've read that it's possible to link JNI library statically (<a href="http://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/invocation.html#library_version" rel="nofollow">http://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/invocation.html#library_version</a>) but I fail to do it with Android Studio. Is it possible?</p>
  
  <p>Here's what I have currently.</p>
  
  <p>In Java code:</p>
  
  <pre><code>System.loadLibrary("testlibrary");
  </code></pre>
  
  <p>In cmake makefile:</p>
  
  <pre><code>add_library( testlibrary
           STATIC
           ${mysources} )
  target_link_libraries(testlibrary)
  </code></pre>
  
  <p>In C++ file:</p>
  
  <pre><code>extern "C" {
  EXPORT
  JNIEXPORT jint JNICALL JNI_OnLoad_testlibrary(JavaVM *vm, void *reserved) {
     ...
     return JNI_VERSION_1_8;
  }
  </code></pre>
  
  <p>When built with Android Studio application fails because it tries to find *.so library file:</p>
  
  <blockquote>
    <p>java.lang.UnsatisfiedLinkError:
    dalvik.system.PathClassLoader[DexPathList[[zip file
    "/data/app/xxx-1/base.apk"],nativeLibraryDirectories=[/vendor/lib,
    /system/lib]]] couldn't find "libtestlibrary.so"</p>
  </blockquote>