title: How to use .so file in Android code to use the native methods
body: <p>I have libmath.so file which have native methods in it. I need to call the native methods in my android code. I have created a sample android application and added the libmath.so inside libs/armeabi folder, Then ran "Right-click mouse" -> Android Tools -> Add native support. Now the following files with below content are created inside jni folder of the application.</p>
  
  <p><strong>Android.mk</strong></p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
  LOCAL_MODULE    := libmath
  LOCAL_SRC_FILES := libmath.cpp
  include $(BUILD_SHARED_LIBRARY)
  </code></pre>
  
  <p><strong>libmath.cpp</strong></p>
  
  <pre><code>#include &lt;jni.h&gt;
  </code></pre>
  
  <p>When I run the Project as android application it shows as follows in the console :-</p>
  
  <pre><code>17:58:41 **** Build of configuration Default for project math ****
  "F:\\Vinay\\Softwares\\android-ndk-r10d\\ndk-build.cmd" all 
  [armeabi] Compile++ thumb: math &lt;= libmath.cpp
  [armeabi] StaticLibrary  : libstdc++.a
  [armeabi] SharedLibrary  : libmath.so
  [armeabi] Install        : libmath.so =&gt; libs/armeabi/libmath.so
  17:58:53 Build Finished (took 11s.695ms)
  </code></pre>
  
  <p>Here is the code how I am loading the library:-</p>
  
  <pre><code>public class MathJni {
  static {
      System.loadLibrary("math");
  }
  public native String calc(String paramString);
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public static final MathJni math = new MathJni();
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          String s= math.calc("help");
  
      }
  </code></pre>
  
  <p>Once after running the android application when I launch the application through emulator I am getting the below error.</p>
  
  <pre><code>02-06 07:38:36.900: D/dalvikvm(831): Trying to load lib /data/app-lib/com.example.math-2/libmath.so 0xb3cd0848
  02-06 07:38:36.900: D/dalvikvm(831): Added shared lib /data/app-lib/com.example.math-2/libmath.so 0xb3cd0848
  02-06 07:38:36.910: D/dalvikvm(831): No JNI_OnLoad found in /data/app-lib/com.example.math-2/libmath.so 0xb3cd0848, skipping init
  02-06 07:38:37.540: W/dalvikvm(831): No implementation found for native Lcom/example/math/MathJni;.calc:(Ljava/lang/String;)Ljava/lang/String;
  02-06 07:38:37.540: D/AndroidRuntime(831): Shutting down VM
  02-06 07:38:37.550: W/dalvikvm(831): threadid=1: thread exiting with uncaught exception (group=0xb3a20ba8)
  02-06 07:38:37.570: E/AndroidRuntime(831): FATAL EXCEPTION: main
  02-06 07:38:37.570: E/AndroidRuntime(831): Process: com.example.math, PID: 831
  02-06 07:38:37.570: E/AndroidRuntime(831): java.lang.UnsatisfiedLinkError: Native method not found: com.example.math.MathJni.calc:(Ljava/lang/String;)Ljava/lang/String;
  02-06 07:38:37.570: E/AndroidRuntime(831):  at com.example.math.MathJni.calc(Native Method)
  02-06 07:38:37.570: E/AndroidRuntime(831):  at com.example.math.MainActivity.onCreate(MainActivity.java:16)
  </code></pre>
  
  <p>What can be the possible reason for this error.</p>