Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load native library on android?

I've got a .so library, which I've extracted from an other APK.

I've copied it into /libs/armeabi location in my project.

In my class, I'm loading it with

static {
    System.loadLibrary("mylib"); 
}

The app crashes with

08-03 07:52:08.089: E/AndroidRuntime(932): FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

Caused by: java.lang.UnsatisfiedLinkError: Couldn't load mylib: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at com.example.mytestandroidapp.MainActivity.<clinit>(MainActivity.java:11)
08-03 07:52:08.089: E/AndroidRuntime(932):  ... 15 more

I'm doing this in eclipse.

Here's the screen of the layout of my project:

enter image description here

What should I do for this to start working?

like image 820
Arsen Zahray Avatar asked Mar 03 '26 11:03

Arsen Zahray


2 Answers

rename mylib.so in libmylib.so, and run your programm again (without modify the loadLibrary argument)

like image 149
Blackbelt Avatar answered Mar 04 '26 23:03

Blackbelt


"rename mylib.so in libmylib.so, and run your programm again (without modify the loadLibrary argument)" from blackbelt

+

The folder libs/armeabi-v7a should also contain the libmylib.so library. If your phone is a new one, he will check there for libraries.

like image 30
Hans Hardmeier Avatar answered Mar 05 '26 00:03

Hans Hardmeier