问题描述
我正在开发包含以下依赖性的应用程序
模块级别
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 }
我的
/资产/150kb使用字体令人难以达到的文件.
/java - 644 kb
/res-740 kB(使用高分辨率图像1920 * 1280尺寸220kb压缩Tinypng)
已经申请了proguard. 删除未使用的文件和代码.
问题
仍然我的应用尺寸为7.03MB
如何减少应用程序大小?我不知道为什么这是7.03MB
是否有任何计算,它给出了APK依赖性使用的大小?
像Google Play服务一样,APK占用了大约200KB.
推荐答案
在6.5之前的Google Play服务版本中,您必须编译 整个API包到您的应用程序中.在某些情况下,做得这么做 保持应用程序中的方法数量更难(包括 框架API,图书馆方法和您自己的代码)在65,536下 限制.从版本6.5,您可以选择性地编译Google Play 服务API到您的应用程序.例如,仅包括谷歌 适合和Android佩戴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
其他推荐答案
而不是编译完整的google服务包,您只能调用您编译所需的包.下面有一个链接,请检查相同 https://developers.google.com/android/guides/setup
在使用GCM之前,我建议您使用Firebase Cloud Messaging,因为Google正在将其基础从GCM转换为Firebase.
Firebase Cloud Messaging的链接: -
https://firebase.google.com/docs/cloud-messaging/Android/Client
可以帮助您的积分: -
您可以在设计中使用FONTAWESOME图标而不是图像,对应用程序大小产生很大影响.为每个重新调度提供Dimen.xml中每个布局的特定大小.
如果您使用的是图像,那么您必须确保未插入不同屏幕的相同图像.尽量使用Android的内置图标,尽可能多地
其他推荐答案
有两个有用的技术,您可能缺少
优化dex和资源以及proguard
这会导致较小的代码,因此只能在发布构建中使用.否则,在调试期间会导致困难.它可以如下实现:
android {
buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }
您还需要专注于从依赖的SDK中删除未使用的字符串.
- 用Resconfigs删除未使用的配置
许多像支持/Google Play Services的库配有字符串资源,以太多语言翻译.您可能不会打算支持所有这些.使用以下方式,您可以控制大小:
android { defaultConfig { ... resConfigs "en" } }
这将删除不是英语的所有资源.
问题描述
I am developing application which contains below dependency
Module level
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**
}
Project level
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 }
my
/Assets /150kb using font aweasome file.
/java - 644 KB
/res - 740 KB (used high resolution image 1920*1280 size 220kb compress with tinypng)
Already applied ProGuard. delete unused file and codes.
Question
Still my app size is 7.03MB
How can i reduce app size? i don't know why this is 7.03MB
Is there any calculation which give size that used by dependency in apk?
Like google play service occupied around 200kb in apk.
推荐答案
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.
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:
Replace
compile 'com.google.android.gms:play-services:9.6.1' //or the version you are using
with specific api's you need:
com.google.android.gms:play-services-gcm:9.6.1 // and other if you need
List of dependencies for specific GMS apis can be found here.
其他推荐答案
Instead of compiling full google services package, you can just call the packages that you need for compiling. There is a link below, kindly check the same https://developers.google.com/android/guides/setup
Before using the GCM, I suggest you to use Firebase Cloud Messaging, as google is shifting its base from gcm to firebase.
Link for Firebase Cloud messaging:-
https://firebase.google.com/docs/cloud-messaging/android/client
Points which can help you:-
You can use FontAwesome Icons in designs instead of images, that has a great impact on Application Size. Provide a specific size for each layout in dimen.xml for every resoultion.
If you are using image then you have to make sure that you are not inserting the same image for different screen. Try to use builtin icons of android as much as possible
其他推荐答案
There are two useful techniques which you might be missing
Optimizing Dex and Resources along with proguard
This results in smaller code so should be used in release build only. Otherwise it will cause difficult during debugging. It can be achieved as follows:
android {
buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }
You also need to focus on removing unused string from dependent SDKs.
- Removing unused configuration with ResConfigs
Many libraries like support/Google play services comes with string resources translate in too many languages. You might not be intending to support all of them. Using following way, you can control the size:
android { defaultConfig { ... resConfigs "en" } }
This will remove all the resources that are not meant for English.