android static library bad ELF number

孤街醉人 提交于 2020-08-26 04:21:14

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/37595807/android-static-library-bad-elf-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!