如何减少 apk 中的 GMS 大小

How to reduce GMS size in apk

我正在尝试减小我的免安装应用程序 apk 的大小。我设法将主模块分成几个较小的模块(功能和库)。一旦应用程序 built,apk 文件的大小(启用缩小):4.9 MB(基本功能)、5 MB(ui 功能 - 活动、片段、接收器等)和 1.3MB(项目详细信息功能)。问题是我不知道我还能从模块中删除什么,因为使用最多大小的包是... com.google.android.gms.internal(下面的屏幕)。

基础特征:

UI 特点:

我怕再拆分那些模块,这个库的问题还是会存在。我真的快要完成我的应用程序的即时应用程序了,但由于文件太大,我无法上传这些文件。任何人都可以知道如何解决这个问题吗?

通常,您可以对 reduce APK size 执行以下操作。

文档范围内的方法。

  1. Reduce resource count and size

    One of the simple ways to make your APK smaller is to reduce the number and size of the resources it contains. In particular, you can remove resources that your app no longer uses, and you can use scalable Drawable objects in place of image files.

    • 删除未使用的资源
    • 尽量减少图书馆的资源使用
    • 仅支持特定密度
    • 使用可绘制对象
    • 重用资源
    • 从代码渲染
    • 压缩 PNG 文件
    • 压缩 PNG 和 JPEG 文件
    • 使用 WebP 文件格式
    • 使用矢量图形
    • 为动画图像使用矢量图形
  2. Reduce native and Java code

    • 删除不必要的生成代码
    • 避免枚举
    • 减小本机二进制文件的大小
    • 删除调试符号
    • 避免提取本机库
  3. Maintain multiple lean APKs

Your APK can contain content that users download but never use, like regional or language information. To create a minimal download for your users, you can segment your app into several APKs, differentiated by factors such as screen size or GPU texture support.

另一个参考 Shrink Your Code and Resources

To make your APK file as small as possible, you should enable shrinking to remove unused code and resources in your release build. This page describes how to do that and how to specify what code and resources to keep or discard during the build.

如果您使用的是 AdMob,play-services-ads:19.6.0 大约需要 2.1Mb。 您可以尝试精简版 (< 500Kb),如果它适用于您的应用程序

https://developers.google.com/admob/android/lite-sdk