“dlopen 失败:是 32 位而不是 64 位"仅在测试中 [英] "dlopen failed: is 32-bit instead of 64-bit" in tests only

查看:58
本文介绍了“dlopen 失败:是 32 位而不是 64 位"仅在测试中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用基于 C++ 代码的核心模块的集合或 Gradle 模块:

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

  • 核心(C++ 使用 JNI 胶水,aar 使用 libxyz-jni.so)
  • 测试(Android 仪器测试)
  • 应用(常规 Android 应用)

Core 模块包括为 armeabi-v7ax86 编译的原生 32 位 libxyz-jni.so 和编译为aar.它没有 arm64 库.

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 模块依赖于 Core 并且在 arm64 硬件设备上运行没有任何问题(能够加载 libxyz-jni.so)

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

Tests 依赖于 Core 并且无法加载 libxyz-jni.so(使用 System.loadLibrary(..)) 出现以下错误:

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" 是 32 位而不是 64 位.

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

我已经检查过测试 apk 不包含除了 armeabi-v7ax86 之外的任何架构.测试可以在 android 模拟器中运行,但不能在带有 Android Nougat 的 64 位硬件设备上运行.该应用程序可以在 arm64 设备上运行.

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?

推荐答案

您应该检查您的应用程序在运行时使用了哪些库.您可以使用以下命令执行此操作:

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

正如你在本例中看到的,Android 已经加载了 lib64 库.如果您希望它默认加载 32 位库,则您的 APK 中需要有 lib/armeabi-v7a/lib.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.

如果您在 APK 中的其他位置拥有您的库,并且您提取和动态加载,Android 将不会知道它们是 32 位的.

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

这篇关于“dlopen 失败:是 32 位而不是 64 位"仅在测试中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆