2016-10-03 96 views
2

我开发的应用程序,包括下面的依赖如何降低的Android的.apk大小

模块级

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:[email protected]' **// For bar graph** 
compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
    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使用字体aweasome文件。

/JAVA - 644 KB

/RES - 740 KB(用于高分辨率图像1920 * 1280尺寸220KB压缩与tinypng)

已经施加ProGuard的。 删除未使用的文件和代码。

问题

不过我的应用程序大小为7.03MB

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

是否有任何计算给出了apk中依赖关系所使用的大小?

像谷歌播放服务在apk中占用200kb左右。

+2

您已经编译**所有** Google Play服务,而不仅仅是** GCM –

+0

针对不同的处理器体系结构(如Armb,x86等)创建不同的版本,而不是通用apk文件。并按照以下文章https://medium.com/pregbuddy-engineering/how-we-reduced-our-android-app-size-by-65-54b17ae9a3c6#.eiqa5xsmh – HourGlass

+0

请参阅https://developers.google。 com/android/guides/setup或使用FCM,因为您已经拥有Firebase Core –

回答

1

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

从版本6.5开始,您可以选择性地将Google Play 服务API编译到您的应用中。例如,只包括谷歌 飞度和Android Wear的API,替换下面的行中的 的build.gradle文件:

更换

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

与特定的API,你需要:

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

特定GMS apis的依赖列表可以在here找到。

+0

它将有助于减少 - 0.5 MB约 我使用shrinkResources它将减少-0.3 Mb左右 仍然应用程序大小为6.40 MB –

2

而不是编译完整的谷歌服务包,你可以调用你需要编译的包。下面有一个链接,请查看相同的 https://developers.google.com/android/guides/setup

使用GCM之前,我建议你使用火力地堡云端通讯,随着谷歌从GCM改变其基地火力地堡。

的火力地堡云消息链接: -

https://firebase.google.com/docs/cloud-messaging/android/client

点,这可以帮助你: -

您可以使用FontAwesome图标的设计,而不是图片,是对应用程序大小有很大的影响。为每个分析提供dimen.xml中每个布局的特定大小。

如果您使用的图像,那么你必须确保你没有插入不同的屏幕相同的图像。尝试尽可能多地使用android的内置图标

+0

我已经实施GCM @kishna。 147 –

+0

@ RRR_1173我编辑了我的答案,请检查它是否可以帮助你 –