简体   繁体   English

如何在 Unity 中减小 APK 文件的大小?

[英]How to reduce the size of an APK file in Unity?

Is the minimum APK size of an Android app made by Unity 8MB? Unity制作的Android应用的最小APK大小是8MB吗? I am building an empty project, but still getting 8MB.我正在构建一个空项目,但仍然有 8MB。 Is there a way to reduce the APK size?有没有办法减小 APK 的大小?

For reducing APK size : 减少 APK 大小

In Unity 5.6.0f3 I have created a simple "Hello world" program and build an APK file, it consumes 21.2 MB at first but to reduce the size you have to follow these steps:在 Unity 5.6.0f3 中,我创建了一个简单的“Hello world”程序并构建了一个 APK 文件,它最初消耗 21.2 MB,但要减小大小,您必须按照以下步骤操作:


  1. Unity 5.6.0f3: Player settings > other settings > optimization > API compatibility level Unity 5.6.0f3:播放器设置>其他设置>优化>API兼容级别

    Unity 2018.3.6f1: Player Settings > Other Settings > Configuration > API Compatibility Level Unity 2018.3.6f1:播放器设置 > 其他设置 > 配置 > API 兼容级别

    .NET 2.0 Subset. .NET 2.0 子集。

    To avoid memory wastage, Unity also supports the .NET 2.0 Subset API profile.为避免内存浪费,Unity 还支持 .NET 2.0 Subset API 配置文件。 This is very similar to the Mono "MonoTouch" profile, so many limitations of the "MonoTouch" profile also apply to Unity's .NET 2.0 Subset profile.Unity's .NET 2.0 Subset profile.这与 Mono“MonoTouch”配置文件非常相似,因此“MonoTouch”配置文件的许多限制也适用于 Unity 的 .NET 2.0 子集配置文件。Unity 的 .NET 2.0 子集配置文件。

  2. Unity 5.6.0f3: Player settings > other settings > device filter > ARMv7 Unity 5.6.0f3:播放器设置>其他设置>设备过滤器>ARMv7

    Unity 2018.3.6f1: Player Settings > Other Settings > Configuration > Target Architectures Unity 2018.3.6f1:播放器设置 > 其他设置 > 配置 > 目标架构

    ARM and x86 are both processor architectures. ARM 和 x86 都是处理器架构。 x86 belongs to Intel while ARM is used by different companies and widely used, so no need to select both architectures. x86 属于 Intel,而 ARM 则为不同公司所使用且广泛使用,因此无需同时选择这两种架构。

  3. Unity 5.6.0f3: Player settings > other settings > rendering path > Legacy Vertex Unity 5.6.0f3:播放器设置>其他设置>渲染路径>旧顶点

  4. Unity 5.6.0f3: Player settings > other settings > Optimization > Stripping level > Use micro mscorlib Unity 5.6.0f3:播放器设置>其他设置>优化>剥离级别>使用micro mscorlib

    The Lightweight mscorlib version will be used at expense of limited compatibility.轻量级 mscorlib 版本的使用将以有限的兼容性为代价。

    Most games do not use all the functionality of the provided DLLs.大多数游戏不使用提供的 DLL 的所有功能。 With this option, you can strip out unused parts to reduce the size of the built player on Android devices.使用此选项,您可以去除未使用的部分以减小 Android 设备上内置播放器的大小。


After applying all these changes it becomes 10.4 MB.应用所有这些更改后,它变为 10.4 MB。

For reducing IPA size:减小 IPA 大小:

In Xcode, there are few flags you need to set,在 Xcode 中,您需要设置的标志很少,

  • Build Settings-> Enable Objective-C Exception-Yes构建设置-> 启用 Objective-C 异常-是

  • Build Settings-> Enable BitCode-No构建设置-> 启用 BitCode-否

  • Build Settings-> Compress PNG files -No构建设置-> 压缩 PNG 文件-否

In Player settings, Device Filter, Select ARMv7 only在播放器设置、设备过滤器中,仅选择 ARMv7
(In latest unity (2018.1), this can be found as Other Settings, Target Architecture) (在最新的 unity (2018.1) 中,可以在其他设置、目标架构中找到)

Also scroll down, set Stripping level to Use Micro mscorlib同时向下滚动,将剥离级别设置为使用微 mscorlib

These should reduce the size a bit further这些应该进一步减小尺寸

Even though your project doesn't contain any of your code yet, it still contains the Unity libraries and they are a fixed size.即使您的项目还不包含任何代码,它仍然包含 Unity 库并且它们的大小是固定的。 8MB is very small for any Android app, let alone a game. 8MB对于任何 Android 应用程序来说都非常小,更不用说游戏了。 I wouldn't worry about that until later.我不会担心,直到后来。

Unity 2020.3.38f1 A empty project in unity take 6 mb size in ARMv7 and take 12mb size in both ARMv7and ARM 64 during building the apk Unity 2020.3.38f1 unity 中的一个空项目在 ARMv7 中占用 6 mb 大小,在 ARMv7 和 ARM 64 中占用 12mb 大小在构建 apk 期间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM