flutter - 找不到名为 "split-per-abi"的选项

在使用 flutter build apk 构建 APK 文件时,请问什么版本的 Flutter 支持 --split-per-abi 选项。我正在使用 Flutter 1.5.4-hotfix.2 仍然无法访问该选项。
根据文档 Preparing an Android app for release ,

This command results in two APK files:

<app dir>/build/app/outputs/apk/release/app-armeabi-v7a-release.apk
<app dir>/build/app/outputs/apk/release/app-arm64-v8a-release.apk

Removing the --split-per-abi flag results in a fat APK that contains your code compiled for all the target ABIs. Such APKs are larger in size than their split counterparts, causing the user to download native binaries that are not applicable to their device’s architecture.

我怎样才能让它工作?

编辑:它适用于 Flutter 1.7.4

最佳答案

在您的<app dir>/android/app/build.gradle添加 splits此处描述的部分:https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split

基本配置是将其添加到您的 build.gradle

android {
  ...
  splits {

    // Configures multiple APKs based on ABI.
    abi {

      // Enables building multiple APKs per ABI.
      enable true

      // By default all ABIs are included, so use reset() and include to specify that we only
      // want APKs for x86 and x86_64.

      // Resets the list of ABIs that Gradle should create APKs for to none.
      reset()

      // Specifies a list of ABIs that Gradle should create APKs for.
      include "x86", "x86_64", "armeabi", "armeabi-v7a", "arm64-v8a"

      // Specifies that we do not want to also generate a universal APK that includes all ABIs.
      universalApk false
    }
  }
}

然后按照文档中的说明运行命令:

flutter build apk --split-per-abi

以下是支持的 ABI 列表: https://developer.android.com/ndk/guides/abis.html#sa

通过上面的配置,您应该获得所有受支持的 ABI

关于flutter - 找不到名为 "split-per-abi"的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56607075/

相关文章:

android - Flutter 不选择基于 fontWeight 的自定义字体

Flutter - 屏幕的多个文件?

flutter - 如何使 Flutter RaisedButton 处于选中状态

firebase - Flutter 中的 cloud_firestore 和 firebase_a

android - 在模拟器相机应用程序中看不到虚拟场景图像

dart - Flutter:测试是否抛出了特定的异常

dart - Flutter popUntil 抛出Bad state : Future alrea

flutter - 如何在 flutter 中改变英雄动画的速度

android - 在 dart/flutter 项目中包含 C 文件

android - 路由后,TextField 单击重建/重新加载小部件