【问题标题】:What makes the minified Hello World Android APK so large - 800KB?是什么让缩小版的 Hello World Android APK 如此之大 - 800KB?
【发布时间】:2017-06-19 02:20:05
【问题描述】:

这不是对当今 Android 应用程序臃肿的普遍抱怨*,而是一个非常具体的问题

如果您安装 Android Studio 2.3.3 并创建“Hello world”示例应用程序(如 Building your first app official tutorial 中所述),然后构建发布 APK,生成的文件为 825KB(我在 Linux 上测试过,但我怀疑输出在其他操作系统上是相同的)。

我有already enabled ProGuard and there are no images or other resources

默认情况下该 APK 中有什么内容?

为什么?

怎样才能消除臃肿?

相比之下,in 2013 a Hello World appunder 10Kb

* 我记得当时体面的全功能应用只有几百 KB,相比之下,像 Uber 这样的 PWA 是 1% 对应的 Android 应用的大小

【问题讨论】:

  • 一般来说,使用工作室本身的APK Analyzer工具来查看哪些部分占用的空间最多。
  • 这是一个展示如何制作1757 bytes 应用程序的博客 - fractalwrench.co.uk/posts/…

标签: android gradle apk


【解决方案1】:

排除所有 AppCompat 库,您会看到大小减少到大约 100kb。

appcompat v7 会自动附加,即使你根本不使用它

在您的 build.gradle 中,从“依赖项”中排除:compile 'com.android.support:appcompat-v7:26.+

您还必须编辑 res\values\styles.xml 才能变成这样:

<resources><style name="AppTheme" parent="android:Theme.Light"></style></resources>

(确保删除 &lt;!-- Customize your theme here. --&gt; 行)。另外,在MainActivity.java 中,将extends AppCompatActivity 部分更改为

public class MainActivity extends Activity

【讨论】:

  • 已尝试,但没有that library,构建失败并显示Error:(99) Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.
  • 将以下文件:src\main\res\values\styles.xml 更改为:"" 为例。这将取消您使用 AppCompat 的义务,使您能够删除它并显着降低 APK 的大小。如果你愿意,你可以使用另一种风格,但你可以肯定的是,AppCompat 负责你的“裸”apk 重量所有这些数百 kbs。排除 AppCompat,您将拥有一个很小的 ​​apk。祝你好运。
  • 很好,现在只有 107KB。我已将您的建议纳入答案。谢谢!
  • 丹,非常感谢您的耐心和考虑。我很高兴它运作良好。最好的问候。
【解决方案2】:

事实证明,通过删除各种资源并使用疯狂的压缩,一个空的 APK 可以降低到 678 bytes (!)。

感谢Udayraj Deshmukh 指出blog post detailing how to reduce an Android APK's size by 99.99%

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    • 2023-01-10
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 2020-05-01
    • 2017-06-14
    相关资源
    最近更新 更多