如何减小 Android Apk 大小 [英] How to reduce Android Apk size

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

问题描述

我正在开发包含以下依赖项的应用程序

I am developing application which contains below dependency

模块级别

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.google.android.gms:play-services:9.0.0' **// for GCM**
compile 'com.android.support:cardview-v7:23.3.0'
compile 'com.squareup.picasso:picasso:2.5.2' **//Rounding and displaying image from URL**
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.github.lecho:hellocharts-library:1.5.8@aar' **// For bar graph** 
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
    transitive = true;
}
compile 'com.google.firebase:firebase-core:9.0.0' **// Analytics**

}

项目级别

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.2'
    classpath 'com.google.gms:google-services:3.0.0'
    classpath 'io.realm:realm-gradle-plugin:1.0.1' // Database
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

我的

/Assets/150kb 使用字体很棒的文件.

/Assets /150kb using font aweasome file.

/java - 644 KB

/java - 644 KB

/res - 740 KB(使用高分辨率图像 1920*1280 大小 220kb 用 tinypng 压缩)

/res - 740 KB (used high resolution image 1920*1280 size 220kb compress with tinypng)

已应用 ProGuard.删除未使用的文件和代码.

Already applied ProGuard. delete unused file and codes.

问题

我的应用程序大小仍然是 7.03MB

Still my app size is 7.03MB

如何减小应用大小?我不知道为什么这是 7.03MB

How can i reduce app size? i don't know why this is 7.03MB

是否有任何计算可以给出 apk 中依赖项使用的大小?

Is there any calculation which give size that used by dependency in apk?

像 google play 服务在 apk 中占用了大约 200kb.

Like google play service occupied around 200kb in apk.

推荐答案

在 6.5 之前的 Google Play 服务版本中,您必须编译整个 API 包到您的应用程序中.在某些情况下,这样做会使保持应用程序中方法的数量更加困难(包括框架 API、库方法和您自己的代码)在 65,536限制.

In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.

从 6.5 版本开始,您可以选择性地编译 Google Play服务 API 到您的应用程序中.例如,仅包含 GoogleFit 和 Android Wear APIs,在你的build.gradle 文件:

From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:

替换

compile 'com.google.android.gms:play-services:9.6.1' //or the version you are using

您需要特定的 api:

with specific api's you need:

com.google.android.gms:play-services-gcm:9.6.1
// and other if you need

可以在此处找到特定 GMS api 的依赖项列表.

List of dependencies for specific GMS apis can be found here.

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

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