将 minSdkVersion 从 16 更改为 26,版本 APK 大小从 17 MB 增加到 39 MB

wuj*_*jek 7 android apk android-min-sdk

我有一个相对较小且简单的应用程序,它始终生成约 17 MB 的发布 APK 文件。不久前,我注意到 APK 大小增加到了惊人的(对于这个应用程序)39 MB。我追踪了导致它的更改,结果发现相同的代码库,其中唯一的更改是minSdkVersion从 16 到 26 ,没有任何其他更改导致 APK 增加。

奇怪的是,当我解压 APK 时,解压后的目录在磁盘上占用了约 40 MB 的空间。有一些更改,但所有更改都在非常小的文件中,就像 26 版本中缺少一些布局一样,可以忽略不计。40 MB 中最大的部分是 lib 文件夹,其中包含 *.so 库,总计 37 MB,但它们在两个 APK 版本中是相同的。(该应用程序是使用 构建的 Flutter 应用程序flutter build apk --release。)

我实际上不希望也不需要minSdkVersion26,并且会恢复此更改,但我很好奇:

  1. Android 的发展过程中发生了什么变化导致这两个minSdkVersion版本之间的尺寸急剧增加?
  2. 解压后的 APK 大小如何几乎相同?似乎minSdkVersion16 版本时的压缩效果更好?
  3. 如果解压后的目录大小几乎相同,那么大小的增加对最终用户来说真的很重要吗?他们需要下载 17 MB 还是 37 MB?为 26 人构建的应用程序会minSdkVersion在他们的设备上占用更多空间吗?

ian*_*ake 11

这按照以下文档的预期工作android:extractNativeLibs

Whether or not the package installer extracts native libraries from the APK to the filesystem. If set to "false", then your native libraries must be page aligned and stored uncompressed in the APK. Although your APK might be larger, your application should load faster because the libraries are directly loaded from the APK at runtime. On the other hand, if set to "true", native libraries in the APK can be compressed. During installation, the installer decompresses the libraries, and the linker loads the decompressed libraries at runtime; in this case, the APK would be smaller, but installation time might be slightly longer.

The default value is "true" if extractNativeLibs is not configured in AndroidManifest.xml. However, when building your app using Android Gradle plugin 3.6.0 or higher, this property is reset to "false" if it is NOT configured in AndroidManifest.xml and minSdkVersion >= 23.

So you're gaining runtime performance by not extracting native libraries, making for a better user experience. Since the system does not need to decompress the .so file, you're actually saving space on the user's device as well.

As explained in the Reduce your app size:

When building the release version of your app, package uncompressed .so files in the APK by setting android:extractNativeLibs="false" in the <application> element of your app's manifest. Disabling this flag prevents PackageManager from copying .so files from the APK to the filesystem during installation and has the added benefit of making updates of your app smaller.

So while the APK size is, at first, larger, subsequent updates are actually significantly smaller. This is because the Google Play Store automatically only downloads the difference between APKs when doing an app upgrade - by storing the .so file uncompressed, this diff is significantly smaller as additional compression would normally completely change the .so file, rather than only change the parts that actually changed.