I would be now publishing my first app on Google play store. I have already compressed images used in my app. And I have some questions regarding the app size.
The reason you see the increased file size is that APK's are compressed files. Use of Proguard can help - here's a good resource:
http://developer.sonymobile.com/2012/01/31/tips-for-reducing-apk-file-size/
However, I can assure you that you can get millions of downloads without being file-size sensitive. Both from my personal experience but also from looking at Google Play. There are thousands of apps with millions of downloads where the file size greatly exceeds 2MB. In fact, there are many that are around 20MB. In other words, do what you can to keep it small, but don't worry that it will impact use or downloads.
Generally, in ProGuard, you can use the following to shrink your APK (this is in your module's build.gradle
file):
...
android {
...
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
...
}
...
Specifically, look at minifyEnabled true
and shrinkResources true
:
minifyEnabled
is responsible for obfuscating and shrinking your code files (e.g. Java). It is the main feature of ProGuard, and helps to shrink your APK as well as making it difficult to reverse engineer.
shrinkResources
is used to remove unused resource files (such as images and other assets). For example, if you are compiling with an Android library, but you are not using some images in that Android library, they will not be included in the final build. There is a good Android Developers video about it here.
So, Why do I see that much increase in my app size, Can it be minimized ?
The .apk-file
An .apk-file is not magical at all. It's just a bundle of files which represent the content of an Android application. If you open it in a archive-tool (like 7Zip), you can browser and extract it's contents.
Now this apk file is extracted during installation hence there is increase in the size of the App.
Some more detail regarding compilation
What happens to the .java-files?
Well, first they are normally compiled by an installed JDK implementation. After they are compiled (to .class-files), the dx-tool from the Android SDK then cross-compiles those "normal" java-classes into Dalvik-Bytecode.
This "special" java-code is then interpreted by the DVM (Dalvik Virtual Machine), which is based on the opensource JRE-implementation Apache Harmony.
What happens to the resources i put into the /asset-directory?
Android offers the /assets-directory to add some binary raw-files (e.g. a SQLite Database). Files which are put into this directory are not compiled or optimized.
If you put your files into this directory, this is the kind of behavior you would expect from Android.
What happens to the resources i put into the /res/raw-directory?
Like the /assets-directory, you can also put binary (or other) raw-files in here (e.g. HTML-files for the Help-page). These files are compiled/optimized (if possible).
What happens to the Manifest and the other XML-files?
The Android-Manifest and also the other XML-files (Layouts, Strings, etc.) are stored and "compiled" into a binary XML-format. This is a speed-optimization.
So you got the answer why app size is increased after installation.
Now Is it safer to delete them(Android Libraries), & deleting them can help to decrease apk size?
You can remove google-play-services.jar
since it is required only in development environment it's not required in runtime environment.Prompt user to install it from the play store.
Coming to Proguard :: It will remove the unused java classes and will do the code obfuscation.It will not remove unused resources like layout xmls,drawables etc. So my opinion is to run the tool to remove unused resources.
Below are some tips to reduce the size.
You can remove drawable-ldpi folder if you are using it.Since there are no more devices with ldpi screen resolution.
Reduce the use of image drawables(i.e .png or jpg files).Use xml drawables and 9-patch drawables.
Remove any debug info related code.
Avoid code duplication.Follow the principal of Don't Repeat yourself.
I think this is enough to reduce app size in your case.
Following are the ways to reduce the app size. In detail is explained in the following link.
https://medium.com/@fahimsakri/put-your-apks-on-diet-cc3f40843c84#.m860q8s1u
Try enabling http://developer.android.com/tools/help/proguard.html , even without obfuscation. It will remove unused Java code from your dependencies. See if you have unneeded dependencies - JARs that you've added but aren't using Check your resources for large images or other files. You may want to change their format or resolution, or remove them if they're not in use.
You can try another answers and they are very good but there is another small trick for reducing massive amount of apk size.
We use many libraries in our projects. some of them developed in Native language ( c ) and some of them developed for a specific version of architecture.
We have some architecture :
Uncommon
Common
Common
Rare
Rare
Common
Uncommon
You can filter target architectures and remove useless options. for example :
buildTypes {
debug {
...
}
release {
...
ndk {
abiFilters "arm64-v8a", "armeabi-v7a", "x86"
}
}
}