“dlopen failed: is 32-bit instead of 64-bit” in tests only

筅森魡賤 提交于 2020-01-04 03:15:12

问题


I'm having a set or Gradle modules that uses the core module based on c++ code:

  • Core (C++ with JNI glue, aar with libxyz-jni.so)
  • Tests (Android instrumentation tests)
  • App (regular Android app)

Core module includes native 32 bit libxyz-jni.so compiled for armeabi-v7a and x86 and is compiled to aar. It does not have arm64 libraries.

App module depends on Core and is working on arm64 hardware device without any issues (is able to load libxyz-jni.so)

Tests depends on Core and fails to load libxyz-jni.so (with System.loadLibrary(..)) with following error:

java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/package.tests.test-2/lib/arm/libxyz-jni.so" is 32-bit instead of 64-bit.

I've checked tests apk not to contain any arch except armeabi-v7a and x86. The tests can run in android emulator but can't on 64 bit hardware device with Android Nougat. The App can run on arm64 device.

That's the difference between tests and app in terms of loading library?


回答1:


You should check to see what libraries your app is using at runtime. You can do this with these commands:

# get your running pid
adb shell ps | grep <your package name> | tr -s ' ' |  cut -d ' ' -f 2 
32333
adb shell lsof | grep 32333 | grep so
.xxx 32333    u0_a222  mem       REG             259,30    133152       2629 /system/lib64/libcompiler_rt.so
.xxx 32333    u0_a222  mem       REG             259,30     30824       2759 /system/lib64/libmemalloc.so

As you can see in this case Android has loaded lib64 libraries. If you want it to default to loading 32-bit libraries, you need to have lib/armeabi-v7a/lib.so in your APK.

If you have your libraries somewhere else in the APK, and you extract, and load dynamically, Android won't know they are 32bit.



来源:https://stackoverflow.com/questions/44127527/dlopen-failed-is-32-bit-instead-of-64-bit-in-tests-only

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