使用APK Splits进行发布,但不能使用“调试”构建类型 [英] Using APK Splits for Release but not Debug build type

查看:703
本文介绍了使用APK Splits进行发布,但不能使用“调试”构建类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功实施 APK拆分,以便为不同的ABI生成不同的APK。然而,为了提高效率(因为我不需要调试中的非armeabi-v7a APK),我想限制调试版本只能生成armeabi-v7a APK。

如何做到这一点?



这:

  abi {
启用true
reset()
include'x86', 'armeabi-v7a','mips'
universalApk false
}

也许有一些方法可以根据Build类型设置 enable

解决方案

你可以在@ Geralt_Encore的答案上尝试一个变体,它避免了单独的 gradlew 命令。在我的情况下,我只关心使用APK拆分来减少发布的APK文件大小,我想完全在Android Studio中完成此操作。

  splits {
abi {
启用gradle.startParameter.taskNames.contains(:app:assembleRelease)
reset()
include'x86','armeabi -v7a','mips'
universalApk false
}
}

如果应用程序模块的名称不是字面上的 app >,则可能需要将:app



从我所看到的Build |在Android Studio中生成签名的APK菜单项会使用 assembleRelease Gradle目标生成APK。

请注意,使用构建版本重新生成APK,或者您的版本构建未命名为 release ,您需要更改 assembleRelease 相应的目标,例如 assemblePaidRelease 如果您的构建风格是已付款


I've successfully implemented APK Splits so that separate APKs are generated for different ABIs.

However, for efficiency (and since I have no need for non-armeabi-v7a APKs in Debug), I would like to limit Debug builds to only generate armeabi-v7a APKs.

How can this be done?

One idea is with this:

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

Maybe there is some way to set enable based on the Build type?

解决方案

You can try a variation on @Geralt_Encore's answer, which avoids the separate gradlew command. In my case, I only cared to use APK splitting to reduce the released APK file size, and I wanted to do this entirely within Android Studio.

splits {
    abi {
      enable gradle.startParameter.taskNames.contains(":app:assembleRelease")
      reset()
      include 'x86', 'armeabi-v7a', 'mips'
      universalApk false
    }
}

You may need to replace the :app prefix with the name of your application module if it's not literally named app.

From what I've seen, the Build | Generate Signed APK menu item in Android Studio generates the APK using the assembleRelease Gradle target.

Note that if you're generating an APK using build flavors, or your release build isn't named release, you'll need to change the assembleRelease target accordingly, e.g. assemblePaidRelease if your build flavor is paid.

这篇关于使用APK Splits进行发布,但不能使用“调试”构建类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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