如何针对不同的Andr​​oid架构?架构、不同、Andr、oid

2023-09-06 07:27:25 作者:渡口有过寒鸦

我目前使用不使用NDK OpenCV的(OpenCV4Android)库(没有C或C ++ code)。但是,也有.so文件为armeabi,armeabi-V7A,MIPS和x86。如果我包括所有的这些项目,应用程序的大小是30MB,而如果我只包括1,应用程序大小只有9MB。如果我尝试在设备上运行应用程序不具有该设备的架构的.so文件包括,它崩溃,而如果我有它包含.so文件,它的工作原理。

所以,我想放多个APK到不同的设备架构,以减少文件大小。从我所看到的,这只能在Application.mk文件中完成的,但我的库没有之一。有另一种方式针对不同的Andr​​oid架构?

解决方案   

我目前使用不使用NDK OpenCV的(OpenCV4Android)库(没有C或C ++ code)。但是,也有用于armeabi .so文件,armeabi-V7A,MIPS和x86

由于immibis所说的那样,如果有的.so 的文件,那么它是使用NDK。

  

如果我尝试在设备上运行应用程序,这并不包括该设备的结构的.so文件时,崩溃,而如果我有它包含.so文件,它的工作原理。

这取决于设备。许多x86设备有 libhoudini ,它可以运行ARM NDK二进制文件,虽然慢于他们运行本地x86二进制。同样, armeabi-V7 设备可以运行 armeabi NDK的二进制文件,虽然也许更慢,特别是浮点处理使用

  

所以,我想放多个APK到不同的设备架构,以减少文件大小。从我所看到的,这只能在Application.mk文件中完成的,但我的库没有的。

Application.mk 文件只控制那些被编译的,而不是被分发。

  

有另一种方式针对不同的Andr​​oid架构?

使用摇篮为Android,或许在与Android结合工作室和的的 ABI 拆分:

 安卓{  ...  拆分{    ABI {      实现真正的      复位()      包括86,armeabi-V7A,MIPS      universalApk真    }  }} 

ABI 关闭在拆分关闭:

选择采用到具有每个CPU架构不同的APK文件

设置要

的架构白名单

还要求包含所有的架构,与分销渠道使用不通过架构支持单独的APK通用APK

您构建的结果将是CPU架构单独的APK,再加上通用的。

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.

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?

解决方案

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.

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

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.

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.

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.

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

Is there another way to target different Android architectures?

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
    }
  }
}

The abi closure in the splits closure:

opts into having different APK files per CPU architecture

sets up a whitelist of the architectures that you want

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

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