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

查看:535
本文介绍了在Android上将CPU/ABI强制为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中找到了库(通常取自构建目录中的目录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位库.

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/3115956 https://stackoverflow.com/a/27713998/3115956 https://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.

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

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