首页 > 解决方案 > 如何在 Android Studio 中压缩 Kotlin 项目

问题描述

我在 android studio 中创建了一个 android 应用程序,对于编程语言我使用了Kotlin
现在我的应用程序完成了,我想构建我的应用程序,但是在构建应用程序后显示35mb的应用程序大小!!!
我的可绘制文件夹大小有2mb并且没有任何更大的文件,但是为什么我的应用程序大小是35mb ?!!!

为了生成测试 apk 版本,我使用了Build -> Build bundle/Apk -> Build apk from android studio menu。

但是当使用java作为语言时,这个大小是7mb !!!

我该如何解决?

标签: javaandroidkotlin

解决方案


Some random ideas to improve your apk size:

  • Turn on minification (ProGuard or R8, use the property minifyEnabled), recheck your ProGuard files if you are not excluding too much
  • Convert your images to webp files, or vectors, which are even better
  • Add an abiFilter, which excludes ancient ABIs, such as mips
  • Use Android App Bundles, which splits the apk per language, ABI and screen resolution, essentially reducing the delivered APK size
  • Check if you have any libraries you don't use anymore
  • Filter out any unsupported languages with the resConfigs attribute

Android also has a documentation about this, which goes into more detail.


推荐阅读