简体   繁体   English

强制 CPU/ABI 在 Android 上使用 armeabi-v7a

[英]Forcing CPU/ABI to armeabi-v7a on Android

I have an Android app that uses some JNI code.我有一个使用一些 JNI 代码的 Android 应用程序。 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.长话短说(双关语),将 JNI 库转换为 64 位几乎是不可能的,因为这需要进行大量更改。 The code (both Java and JNI) works nicely on armeabi-v7a architecture.代码(Java 和 JNI)在 armeabi-v7a 架构上运行良好。

The libraries are being loaded using loadLibrary.正在使用 loadLibrary 加载库。 When I attempt to run my app on a Nexus 6, the app loads fine.当我尝试在 Nexus 6 上运行我的应用程序时,应用程序加载正常。 As soon as loadLibrary is executed, the app crashes with the error described here .一旦 loadLibrary 被执行,应用程序就会崩溃,并出现此处描述的错误。

The problem, as I understand it, is that when executing on Nexus 6, the app builds as arm64-8a.据我了解,问题在于在 Nexus 6 上执行时,应用程序构建为 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 构建的(因为 64 位版本存在我在问题开始时提到的问题)。

My question is, can I force arm64-8a devices to also run armeabi-v7a code?我的问题是,我可以强制 arm64-8a 设备也运行 armeabi-v7a 代码吗? How do I force my app apk to be armeabi-v7a so it is only 32-bit regardless of device?如何强制我的应用程序 apk 成为 armeabi-v7a,使其无论设备如何都只有 32 位?

Yes, arm64-v8a devices can also run armeabi-v7a code.是的,arm64-v8a 设备也可以运行 armeabi-v7a 代码。

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 后,安装程序会检查软件包是否包含官方目录中的库,并根据结果将活动标记为 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.如果它在 APK 中的lib/arm64-v8a找到库(通常取自 build 目录中的libs/arm64-v8a目录),它将被标记为 64 位,并会忽略所有其他目录。 If it finds libraries in lib/armeabi-v7a or lib/armeabi in the APK, the process is marked as 32 bit.如果它在 APK 中的lib/armeabi-v7alib/armeabi中找到库,则该进程被标记为 32 位。 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 位模式下。

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).现在,如果您确实以 64 位模式发布了一些(但不是全部)库,则该进程将以 64 位模式启动,并且将无法加载 32 位库(甚至不会安装)。 In this case, you must avoid bundling any 64 bit libraries unless all of them are available.在这种情况下,除非所有 64 位库都可用,否则必须避免捆绑任何 64 位库。

Or you don't use the official libs directory but install your libraries some other way (eg by downloading them at runtime or keeping them in eg 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).或者您不使用官方 libs 目录而是以其他方式安装库(例如通过在运行时下载它们或将它们保存在例如资产中),系统不知道您的进程想要以 32 位模式运行库(在这一点切换到其他模式为时已晚)。 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.在这些情况下,请确保以正常/官方方式至少包含一些虚拟库,以便将应用程序标记为 32 位。

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.https://stackoverflow.com/a/33919454/3115956https://stackoverflow.com/a/27713998/3115956https://stackoverflow.com/a/35450911/3115956的答案类似的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 armeabi-v7a与-mfloat-abi =很难 - armeabi-v7a with -mfloat-abi=hard 如何确定 Android .so 文件的 ABI(即 armeabi 或 armeabi-v7a)? - How to determine ABI of Android .so file (i.e. armeabi or armeabi-v7a)? 警告:由 'android.injected.build.abi' 设置的 ABIs [armeabi-v7a,armeabi] gradle 标志包含此项目未针对的 'ARMEABI' - WARNING: ABIs [armeabi-v7a,armeabi] set by 'android.injected.build.abi' gradle flag contained 'ARMEABI' not targeted by this project Android:在aarch64平台上找不到armeabi-v7a abi过滤器的libopencv_java3.so - Android : libopencv_java3.so not found for armeabi-v7a abi filter on aarch64 platform Android Travis CI错误:所选目标的--abi armeabi-v7a无效 - Android Travis CI Error: Invalid --abi armeabi-v7a for the selected target M1 MacBook Pro 上的 Android Studio 无法使用 ABI armeabi-v7a 模拟系统映像 - Android Studio on M1 MacBook Pro Cannot Simulate System Images with ABI armeabi-v7a Google API 的“所选目标的 --abi armeabi-v7a 无效” - “Invalid --abi armeabi-v7a for the selected target” with Google APIs 人行横道项目错误'建筑ABI'armeabi-v7a'失败' - crosswalk-project error ' Building ABI 'armeabi-v7a' failed' Android中的armeabi-v7a拆分apk - armeabi-v7a in Android split apk Android NDK 调试:armeabi-v7a 不工作 - Android NDK debugging: armeabi-v7a not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM