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

查看:253
本文介绍了如何减少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打包到您的应用中.在某些情况下,这样做 保持应用程序中方法的数量(包括 65,536下的框架API,库方法和您自己的代码) 限制.

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集成到您的应用中.例如,仅包含Google Fit和Android Wear API,将以下行替换为 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天全站免登陆