如何减小apk的大小 [英] How to reduce the size of apk

查看:22
本文介绍了如何减小apk的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的资产和可绘制对象只有 2mb,java 和 xml 源只有 1mb,但在构建项目后,apk 大小为 20mb!

我设置了shrinkResources true并删除未使用的资源并使用 proguard 生成应用.

有没有办法减小apk的大小?

解决方案

Android Studio 有自己的 apk 分析器,对于像您这样的情况非常有用.

分析您的 apk 文件并检查哪些文件使用了这么多空间.

还使用 ProGuard 有助于减小 apk 大小.

此外,避免使用不必要的库.例如,

如果您需要使用 Google Analytics,请像这样导入 gradle only 分析库:

编译'com.google.android.gms:play-services-analytics:10.2.4'

不要这样使用:

编译'com.google.android.gms:play-services:10.2.4'

第二个例子使用了太多的空间和冗余的类和文件.

My assets and drawable are only 2mb java and xml sources is only 1mb but after build project the apk size is 20mb!

I set shrinkResources true and remove unused resources and generate app with proguard.

Is there a way to reduce the size of apk?

解决方案

Android Studio has its own apk analyzer which is very useful for cases like yours.

Analyze your apk file and check which files are using this much space.

https://developer.android.com/studio/build/apk-analyzer.html

Also using ProGuard helps to reduce apk size.

Additionally, avoid using unnecessary libraries. For example,

if you need to use Google Analytics, import gradle only analytics library like this:

compile 'com.google.android.gms:play-services-analytics:10.2.4'

do not use like this:

compile 'com.google.android.gms:play-services:10.2.4'

second example uses too much space and redundant classes and files.

这篇关于如何减小apk的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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