强制 CPU/ABI 在 Android 上使用 armeabi-v7a [英] Forcing CPU/ABI to armeabi-v7a on Android

查看:36
本文介绍了强制 CPU/ABI 在 Android 上使用 armeabi-v7a的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 JNI 代码的 Android 应用程序.长话短说(双关语),将 JNI 库转换为 64 位几乎是不可能的,因为这需要进行大量更改.代码(Java 和 JNI)在 armeabi-v7a 架构上运行良好.

I have an Android app that uses some JNI code. Long story short (pun intended), it is nearly impossible to convert the JNI libraries to 64-bit as it would require a lot of changes. The code (both Java and JNI) works nicely on armeabi-v7a architecture.

正在使用 loadLibrary 加载库.当我尝试在 Nexus 6 上运行我的应用程序时,应用程序加载正常.一旦 loadLibrary 被执行,应用程序就会崩溃,错误描述为 这里.

The libraries are being loaded using loadLibrary. When I attempt to run my app on a Nexus 6, the app loads fine. As soon as loadLibrary is executed, the app crashes with the error described here.

据我所知,问题是在 Nexus 6 上执行时,应用程序构建为 arm64-8a.但是这些库不是为 arm64-8a 构建的(因为 64 位版本存在我在问题开头提到的问题).

The problem, as I understand it, is that when executing on Nexus 6, the app builds as arm64-8a. But the libraries are not built for arm64-8a (as the 64-bit version has issues I mentioned at start of the question).

我的问题是,我可以强制 arm64-8a 设备也运行 armeabi-v7a 代码吗?如何强制我的应用程序 apk 为 armeabi-v7a,使其无论设备如何都只有 32 位?

My question is, can I force arm64-8a devices to also run armeabi-v7a code? How do I force my app apk to be armeabi-v7a so it is only 32-bit regardless of device?

推荐答案

是的,arm64-v8a 设备也可以运行 armeabi-v7a 代码.

Yes, arm64-v8a devices can also run armeabi-v7a code.

安装 APK 后,安装程序会检查软件包是否包含官方目录中的库,并根据结果将活动标记为 32 位或 64 位.

When the APK is installed, the installer checks if the package contains libraries in the official directories, and marks the activity as 32 or 64 bit depending on the outcome.

如果它在APK中的lib/arm64-v8a中找到库(通常取自build目录中的libs/arm64-v8a目录),它将标记为 64 位,将忽略所有其他目录.如果它在 APK 中的 lib/armeabi-v7alib/armeabi 中找到库,则该进程被标记为 32 位.如果其中任何一个都没有本机库,则安装程序会假定应用程序根本不使用本机代码,并且可以在任一模式下(实际上是在 64 位模式下)自由运行.

If it finds libraries in lib/arm64-v8a within the APK (normally taken from the directory libs/arm64-v8a in the build directory), it will be marked as 64 bit, and will ignore all other directories. If it finds libraries in lib/armeabi-v7a or lib/armeabi in the APK, the process is marked as 32 bit. If there's no native libraries in any of these, the installer assumes that the application doesn't use native code at all and is free to run it in either mode, in practice in 64 bit mode.

现在,如果您确实以 64 位模式发布了一些库,但不是全部,该进程将以 64 位模式启动,并且将无法加载 32 位库(甚至不会安装).在这种情况下,除非所有 64 位库都可用,否则您必须避免捆绑任何 64 位库.

Now if you do ship some, but not all, libraries in 64 bit mode, the process will be launched in 64 bit mode and will be unable to load the 32 bit libraries (which won't even be installed). In this case, you must avoid bundling any 64 bit libraries unless all of them are available.

或者你不使用官方的 libs 目录而是以其他方式安装你的库(例如通过在运行时下载它们或将它们保存在例如资产中),系统不知道你的进程想要以 32 位运行库模式(此时切换到其他模式为时已晚).在这些情况下,请确保以正常/官方方式至少包含一些虚拟库,以便将应用程序标记为 32 位.

Or you don't use the official libs directory but install your libraries some other way (e.g. by downloading them at runtime or keeping them in e.g. assets), the system has no idea that your process wants to run libraries in 32 bit mode (at which point it is too late to switch to the other mode). In these cases, make sure to include at least some dummy library in the normal/official way, in order to flag the application as 32 bit.

参见https://stackoverflow.com/a/33919454/3115956https://stackoverflow.com/a/27713998/3115956https://stackoverflow.com/a/35450911/3115956 类似问题的答案.

See https://stackoverflow.com/a/33919454/3115956, https://stackoverflow.com/a/27713998/3115956 and https://stackoverflow.com/a/35450911/3115956 for answers to similar issues.

这篇关于强制 CPU/ABI 在 Android 上使用 armeabi-v7a的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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