Note that there are some explanatory texts on larger screens.

plurals
  1. POUnsatisfiedlinkerror in android (eclipse)
    text
    copied!<p>I am trying to run a simple jni code in Android, But all I am getting Unsatisfiedlinkerror .</p> <p>Here is my Java code:</p> <pre><code>package com.lipcap; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends Activity { /** Called when the activity is first created. */ TextView a; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); a=new TextView(this); String b; MainActivity ob=new MainActivity(); b=ob.sniff(); a.setText(b); setContentView(a); } public native String sniff(); static{ System.loadLibrary("native"); } } </code></pre> <p>And here is My C++ code(in $PROJECT_PATH/jni/):</p> <pre><code>#include&lt;iostream&gt; #include&lt;string.h&gt; #include&lt;jni.h&gt; JNIEXPORT jstring JNICALL Java_com_lipcap_MainActivity_sniff (JNIEnv *env, jobject obj){ return env-&gt;NewStringUTF("This is Native"); } </code></pre> <p>I have complied java code using javac, and made the header using javah.</p> <p>Then I ran ndk-build. And then I ran code from eclipse.(installed apk in android).</p> <p>I get this error:</p> <pre><code>E/AndroidRuntime( 769): FATAL EXCEPTION: main E/AndroidRuntime( 769): java.lang.UnsatisfiedLinkError: sniff E/AndroidRuntime( 769): at com.lipcap.MainActivity.sniff(Native Method) E/AndroidRuntime( 769): at com.lipcap.MainActivity.onCreate(MainActivity.java:36) E/AndroidRuntime( 769): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) E/AndroidRuntime( 769): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) E/AndroidRuntime( 769): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) E/AndroidRuntime( 769): at android.app.ActivityThread.access$2300(ActivityThread.java:125) E/AndroidRuntime( 769): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) E/AndroidRuntime( 769): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime( 769): at android.os.Looper.loop(Looper.java:123) E/AndroidRuntime( 769): at android.app.ActivityThread.main(ActivityThread.java:4627) E/AndroidRuntime( 769): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 769): at java.lang.reflect.Method.invoke(Method.java:521) E/AndroidRuntime( 769): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) E/AndroidRuntime( 769): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) E/AndroidRuntime( 769): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>I have not set LD_LIBRARY_PATH.</p> <p>However,without setting LD_LIBRARY_PATH sample code such as HelloJNI provided by NDK runs absolutely fine.</p> <p>Please tell me where i am missing.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload