title: Setting up JNA in Android Studio
body: <p>I try to import jna.jar into my project since <strong>JNA</strong> is a very useful tool to call Native library which is base on JNI.</p>
  
  <p>OS: Windows 10</p>
  
  <p>IDE: Android Studio 1.5.1</p>
  
  <p>JDK: 1.8.0_73</p>
  
  <p>NDK: r10e</p>
  
  <p><strong>What I have done</strong>
  (AS = Android Studio)</p>
  
  <ol>
  <li><p>Create a new project by AS with API18.</p></li>
  <li><p>Download jna.jar from their GitHub.</p>
  
  <blockquote>
    <p><a href="https://github.com/java-native-access/jna" rel="nofollow noreferrer">https://github.com/java-native-access/jna</a></p>
  </blockquote></li>
  <li>copy jna.jar into project folder.
  
  <blockquote>
    <p>JNATest\app\libs\jna.jar</p>
  </blockquote></li>
  <li>In AS, right-click on the icon of jna.jar, choose <strong>Add as Library</strong></li>
  <li>Wait for few seconds, check the File->Project Structure->app->Dependencies. We do have the jna.jar. (Same as app\build.gradle) 
  <a href="https://i.stack.imgur.com/YEmYC.jpg" rel="nofollow noreferrer">build gradle</a></li>
  <li>Implement JAVA code about JNA in MainActivity.java</li>
  <li>Run app on real device Sony Z3 (arm)</li>
  <li>Crash by <code>CLibrary.Instance.printf("Hello, JNA");</code></li>
  </ol>
  
  <p><strong>Error Message on Android Monitor</strong></p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                     Process: i3d.jnatest, PID: 1068
                     java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-arm/libjnidispatch.so) not found in resource path (.)
                       at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:866)
                       at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:826)
                       at com.sun.jna.Native.&lt;clinit&gt;(Native.java:140)
  ..
  ... so on
  </code></pre>
  
  <p><strong>Java code</strong></p>
  
  <pre><code>package i3d.jnatest;
  
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  
  import com.sun.jna.Library;
  import com.sun.jna.Native;
  
      public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          CLibrary.Instance.printf("Hello, JNA");
      }
  
      public interface  CLibrary extends Library
      {
          CLibrary Instance = (CLibrary) Native.loadLibrary("msvcrt", CLibrary.class);
          void printf(String format, Object... args);
      }
  }
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>According to error message, I miss <code>/android-arm/libjnidispatch.so</code> in runtime.</p>
  
  <ol>
  <li><p>Did I put the wrong place for jna.jar?</p></li>
  <li><p>How should I get and use <code>/android-arm/libjnidispatch.so</code>?</p></li>
  </ol>
  
  <p>I am a newbie about Android Studio, so maybe misunderstanding something key-point.</p>