Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android static library bad ELF number

I have build a static library with the Android ndk.

I now try to use this library in another Android project

//in mainActivity
static
{
    System.loadLibrary("MILlib");
}

I got the following error when building the test project

02 17:07:24.890 2785-2785/com.MIL.testlib E/AndroidRuntime: FATAL EXCEPTION: main Process: com.MIL.testlib, PID: 2785 java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/com.MIL.testlib-1/lib/arm/libMILlib.so" has bad ELF magic at java.lang.Runtime.loadLibrary(Runtime.java:371) at java.lang.System.loadLibrary(System.java:989) at com.MIL.testlib.MainActivity.(MainActivity.java:112) at java.lang.reflect.Constructor.newInstance(Native Method) at java.lang.Class.newInstance(Class.java:1650) at android.app.Instrumentation.newActivity(Instrumentation.java:1079) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2640) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2873) at android.app.ActivityThread.access$900(ActivityThread.java:181) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1482) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6145) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

What is a bad ELF magic number and how to solve it ?

like image 895
stephone Avatar asked Feb 07 '23 21:02

stephone


1 Answers

A .so object is a shared object file. This is native code as opposed to a Java library and it is called an ELF because it is in Extensible Linking Format.

The "magic" refers to the first 64 bits of the ELF file. This specifies some header information, including the architecture of the system it was built for.

Android phones support three architectures: ARM, Intel, and MIPS. Emulators support the hardware they are running on, usually Intel. Given that your .so has 'arm' in the directory path, I suspect that your .so is an ARM .so and you are trying to run this on either Intel or MIPS.

like image 58
Robert Mandeville Avatar answered Feb 09 '23 09:02

Robert Mandeville