如何针对不同的 Android 架构? [英] How to target different Android architectures?

查看:32
本文介绍了如何针对不同的 Android 架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用不使用 NDK 的 OpenCV (OpenCV4Android) 库(没有 C 或 C++ 代码).但是,有用于 armeabi、armeabi-v7a、mips 和 x86 的 .so 文件.如果我在项目中包含所有这些,则应用程序大小为 30mb,而如果我只包含 1 个,则应用程序大小仅为 9mb.如果我尝试在没有包含该设备架构的 .so 文件的设备上运行该应用程序,它会崩溃,而如果我包含它的 .so 文件,它会工作.

I am currently using the OpenCV (OpenCV4Android) library which does not use the NDK (there is no C or C++ code). However, there are .so files for armeabi, armeabi-v7a, mips, and x86. If I include all of these in the project, the app size is 30mb, whereas if I include only 1, the app size is only 9mb. If I try to run the app on a device that doesn't have that device's architecture's .so file included, it crashes, whereas if I have it's .so file included, it works.

因此,我想将多个 APK 发布到不同的设备架构以减小文件大小.据我所知,这只能在 Application.mk 文件中完成,但我的库没有.还有其他方法可以针对不同的 Android 架构吗?

Therefore, I am wanting to release multiple APKs to different device architectures to reduce the file sizes. From what I've seen, this can only be done in the Application.mk file, but my library does not have one. Is there another way to target different Android architectures?

推荐答案

我目前正在使用不使用 NDK 的 OpenCV (OpenCV4Android) 库(没有 C 或 C++ 代码).但是,有用于 armeabi、armeabi-v7a、mips 和 x86 的 .so 文件.

I am currently using the OpenCV (OpenCV4Android) library which does not use the NDK (there is no C or C++ code). However, there are .so files for armeabi, armeabi-v7a, mips, and x86.

正如immibis所说,如果有.so文件,那么就是使用了NDK.

As immibis put it, if there are .so files, then it is using the NDK.

如果我尝试在没有包含该设备架构的 .so 文件的设备上运行该应用程序,它会崩溃,而如果我包含它的 .so 文件,它会工作.

If I try to run the app on a device that doesn't have that device's architecture's .so file included, it crashes, whereas if I have it's .so file included, it works.

这取决于设备.许多 x86 设备都有 libhoudini,它可以运行 ARM NDK 二进制文件,尽管比运行原生 x86 二进制文件要慢.同样,armeabi-v7 设备可以运行 armeabi NDK 二进制文件,但速度可能会更慢,尤其是在使用浮点处理的情况下.

That depends upon the device. Many x86 devices have libhoudini, which can run ARM NDK binaries, albeit more slowly than they would run native x86 binaries. Similarly, an armeabi-v7 device can run armeabi NDK binaries, though perhaps more slowly, particularly if floating-point processing is used.

因此,我想将多个 APK 发布到不同的设备架构以减小文件大小.据我所知,这只能在 Application.mk 文件中完成,但我的库没有.

Therefore, I am wanting to release multiple APKs to different device architectures to reduce the file sizes. From what I've seen, this can only be done in the Application.mk file, but my library does not have one.

Application.mk 文件只控制编译的内容,而不控制分发的内容.

The Application.mk file only controls what gets compiled, not what gets distributed.

还有其他方法可以针对不同的 Android 架构吗?

Is there another way to target different Android architectures?

使用 Gradle for Android,可能与 Android Studio 结合使用,以及 abi 拆分:

Use Gradle for Android, perhaps in conjunction with Android Studio, and the abi split:

android {
  ...
  splits {
    abi {
      enable true
      reset()
      include 'x86', 'armeabi-v7a', 'mips'
      universalApk true
    }
  }
}

splits 闭包中的 abi 闭包:

  • 选择为每个 CPU 架构使用不同的 APK 文件

  • opts into having different APK files per CPU architecture

设置所需架构的白名单

还请求包含所有架构的通用 APK",用于不支持按架构划分的单独 APK 的分发渠道

also requests a "universal APK" that contains all of the architectures, for use with distribution channels that do not support separate APKs by architecture

您的构建结果将是按 CPU 架构划分的单独 APK,加上通用的.

The result of your build will be separate APKs by CPU architecture, plus the universal one.

这篇关于如何针对不同的 Android 架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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