Search code examples
androidandroid-ndk-r5

java.lang.ExceptionInInitializerError Caused by: java.lang.UnsatisfiedLinkError: Library not found


I have existing code in c and c++. I have added these c files and cpp files in Android.mk file. And I have successfully created the .so files named itv.so in my application. But now when I am trying to run Android application It is showing error like...

12-20 13:26:31.362: E/AndroidRuntime(716): FATAL EXCEPTION: main
12-20 13:26:31.362: E/AndroidRuntime(716): java.lang.ExceptionInInitializerError
12-20 13:26:31.362: E/AndroidRuntime(716):  at com.example.Internet_TV12.onCreate(Internet_TV12.java:38)
12-20 13:26:31.362: E/AndroidRuntime(716):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-20 13:26:31.362: E/AndroidRuntime(716):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-20 13:26:31.362: E/AndroidRuntime(716):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-20 13:26:31.362: E/AndroidRuntime(716):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-20 13:26:31.362: E/AndroidRuntime(716):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-20 13:26:31.362: E/AndroidRuntime(716):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 13:26:31.362: E/AndroidRuntime(716):  at android.os.Looper.loop(Looper.java:123)
12-20 13:26:31.362: E/AndroidRuntime(716):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-20 13:26:31.362: E/AndroidRuntime(716):  at java.lang.reflect.Method.invokeNative(Native Method)
12-20 13:26:31.362: E/AndroidRuntime(716):  at java.lang.reflect.Method.invoke(Method.java:521)
12-20 13:26:31.362: E/AndroidRuntime(716):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-20 13:26:31.362: E/AndroidRuntime(716):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-20 13:26:31.362: E/AndroidRuntime(716):  at dalvik.system.NativeStart.main(Native Method)
12-20 13:26:31.362: E/AndroidRuntime(716): Caused by: java.lang.UnsatisfiedLinkError: Library itv not found
12-20 13:26:31.362: E/AndroidRuntime(716):  at java.lang.Runtime.loadLibrary(Runtime.java:461)
12-20 13:26:31.362: E/AndroidRuntime(716):  at java.lang.System.loadLibrary(System.java:557)
12-20 13:26:31.362: E/AndroidRuntime(716):  at com.example.Display.<clinit>(Display.java:69)
12-20 13:26:31.362: E/AndroidRuntime(716):  ... 14 more

I don't know why this error is coming. I have seen lib folder which is having libitv.so file. I have also tried

static {
         try {
             System.loadLibrary("itv");
           // System.load("/data/data/com/example/lib/itv.so");
         }
         catch (UnsatisfiedLinkError use) {
                Log.e("JNI", "WARNING: Could not load itv.so");
            }
        }

But getting same error. Can anybody please tell me the solution for this error. Thank you in Advance.


Solution

  • The library will be recognised if its name is libitv.so and is placed in libs\armeabi directory in your application directory, before the .apk is built.

    Sometimes when the library is not copied completely(partial copy), due to some system issues the partial library too will not be recognized.