设置 android:extractNativeLibs=false 以减少应用程序大小 [英] Setting android:extractNativeLibs=false to reduce app size

查看:51
本文介绍了设置 android:extractNativeLibs=false 以减少应用程序大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定,如果我做对了.它似乎正在做相反的事情.如果我将标志 android:extractNativeLibs 设置为 true,则应用程序占用了大约 70MB 的用户空间(是的...)但是如果我将此标志设置为 false,则安装在设备上的应用程序的大小会跳到大约 95MB.所以我不确定用户是否会喜欢这个.

I am not sure, if I got this right. It seems it is doing the oposite. If I keep the flag android:extractNativeLibs set to true, the app is taking about 70MB of user's space (yeah...) but if I set this flag to false, the size of the app installed on the device jumps to about 95MB. So I am not sure if user would appreciate this.

推荐答案

这有点棘手.当extractNativeLibs 设置为false 时,您的APK 大小将会更大.

This is a bit tricky. Your APK size is going to be larger when extractNativeLibs is set to false.

当 extractNativeLibs 设置为 true(默认)或未添加到清单时,您的本机库可以压缩存储在 APK 中.它们在安装期间由 PackageManager 提取,并将副本放入/data/app/.结果,本机库有两个副本——一个在 APK 中压缩,一个在/data/app/中未压缩.

When extractNativeLibs is set to true (default) or not added to the manifest, your native libraries can be stored compressed in the APK. They are extracted by the PackageManager during installation, and a copy is put to /data/app/. As a result, there are two copies of the native library - a compressed in the APK, and an uncompressed in /data/app/.

这种方法有以下优点:

  • 更小的 APK 大小,因为库被压缩

缺点:

  • 增加了安装大小(设置"=>应用"中的存储"或磁盘上"),因为除了 APK 之外,提取的本机库还占用磁盘空间
  • 更长的安装时间
  • 来自 Google Play 的优化较少,例如在生成更新补丁时

Google 在 Marshmallow (Android 6) 中引入的新方法是通过将 extractNativeLibs 设置为false"来启用的.它期望存储在 APK(存储方法)和 zipaligned 中的库未压缩.安装过程中无需提取它们.在应用启动时,可以直接从 APK 加载(memmapped)库.

New approach introduced by Google in Marshmallow (Android 6) is enabled by setting extractNativeLibs to "false". It expects the libraries stored uncompressed in the APK (STORE method) and zipaligned. There's no need to extract them during installation. On app startup, the libraries can be loaded (memmapped) directly from the APK.

优点:

  • 减小了安装大小(设置"=>应用"中的存储"或磁盘上"),因为无需提取库.基本上,占用的空间通常只是比 APK 大小多一点
  • Google Play 的下载大小没有增加,因为它在 APK 之上使用了自己的压缩
  • 优化了 Google Play 的更新补丁生成,从而缩小了更新大小.如果您更新您的原生库,压缩版本将有巨大差异,导致补丁更大,而未压缩库的补丁将相对较小.

缺点:

  • 更大的 APK 大小,因为原生库没有被压缩

不出所料,我没有发现两个选项的加载性能有明显差异.

Expectedly, I didn't find a noticeable difference in loading performance of both options.

extractNativeLibs="false";选项可能对您有用:

The extractNativeLibs="false" option could be useful for your if:

  • 您不关心 APK 大小 - 要么远低于 100 Mb 限制,要么您已经在使用扩展文件 (OBB) 并且可以处理 APK 大小增加
  • 您关心您的应用在 Google Play 中的更新大小
  • 您的本地库不是很大.

例如,对于使用 Unity 制作的游戏,由于本地库很大,此选项几乎不适用.

For example, for a game made with Unity, this option is hardly applicable because of the large native libraries.

Android App Bundles 是 Google Play 宣布的一种新的分发机制,更多详情请访问官方网站 https://developer.android.com/platform/technology/app-bundle/https://developer.android.com/guide/app-bundle/

Android App Bundles are a new distribution mechanism announced by Google Play, more details available on the official websites https://developer.android.com/platform/technology/app-bundle/ and https://developer.android.com/guide/app-bundle/

与传统 APK 相比,它具有显着的优势,最重要的优势之一是 150 Mb 的最大大小限制.重要提示:这是下载大小,而不是应用程序包本身或生成的 APK 的大小.(APK 由 Play 生成并即时传送到设备,有关其工作原理的更多详细信息应在官方 Android 资源中提供).

It has significant advantages over a traditional APK, one of the most important being the 150 Mb max size limit. Important: this is the download size, not the size of the app bundle itself or the generated APK. (APKs are generated by Play and delivered to the device on-the-fly, more details on how it works should be available on official Android resources).

在构建 AAB 时,它的 extractNativeLibs 标志设置为false";默认情况下.但是,由于 Google Play 会在传送到终端设备的 APK 之上应用压缩,因此这不会影响下载大小.这意味着此标志只会在 Android App Bundle 的情况下带来好处 - 安装速度更快,磁盘空间更小,几乎没有额外成本,因为没有达到最大大小限制的压力.

When building an AAB, it has the extractNativeLibs flag set to "false" by default. However, as Google Play applies compression on top of the APKs delivered to the end device, this doesn't affect the download size. It means that this flag brings only benefits in case of Android App Bundles - faster installation, less size on disk at almost no additional cost because of no pressure towards the max size limit.

然而,一个令人困惑的事情是当您接近 150 Mb 限制时如何计算下载大小,因为 AAB 大小并不表示下载大小.在 bundletool https 中有一个特殊的命令://developer.android.com/studio/command-line/bundletool#measure_size,或者您可以尝试将其直接上传到Play.如果您的 AAB 远低于 150 Mb,则无需担心.

One confusing thing however is how to calculate the download size when you're close to the 150 Mb limit, because the AAB size is not an indication of the download size. There is a special command for that in the bundletool https://developer.android.com/studio/command-line/bundletool#measure_size, or you can try uploading it to Play directly. If your AAB is well under 150 Mb, there's no need to worry then.

(更新:对应用程序包使用 150 Mb 大小限制而不是 500 Mb;显然 500 MB 在开发者预览版中可用,但目前尚未公开).

(Update: using 150 Mb size limit instead of 500 Mb for app bundles; apparently 500 MB was available in developer preview but is not public as of now).

这篇关于设置 android:extractNativeLibs=false 以减少应用程序大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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