Reducing APK size by removing mdpi - android

I am trying to reduce my apk size. Currently it is 7 Mb after using Proguard. It's a very huge size for a small app. So can I remove mdpi and xxhdpi images from /drawable?

Use folllowing property of proguard
minifyEnabled true
shrinkResources true
You can reduce PNG file sizes without losing image quality using tools like pngcrush, pngquant, or zopflipng. All of these tools can reduce PNG file size while preserving image quality.
There are also more tricks and methods For More info in Details Read the Official Documentation of Android Developer

Quoting from Reduce apk size|Android Developers
If you know that only a small percentage of your users have devices with specific densities, consider whether you need to bundle those densities into your app. If you don't include resources for a specific screen density, Android automatically scales existing resources originally designed for other screen densities.
You can remove mdpi drawables if you are sure enough that most of your user don't use devices which supports mdpi drawables.
In case of xxhdpi the page Reduce apk size|Android Developers suggests
We recommend that every app include at least an xxhdpi image variant.
So you should keep xxhdpi according to this.

Related

Android xxxhdpi drawable resolution auto resize

If I add a large image to xxxhdpi folder does it gets resized automatically by Android to smaller images for other screen resolutions?
And if yes from which version of Android is this supported?
You shouldn't really need xxxhdpi. It was only introduced because of the way that launcher icons are scaled on the Nexus 5's launcher.
So throw your image into xxhdpi and it will scale down for other devices. The only issue you'll have is quality. You'd get higher quality out of the image if you scale it yourself.
Adding to my comment, this is from Android Developers - Supporting Multiple Screens.
Provide different bitmap drawables for different screen densities
By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and Nine-Patch drawables (.9.png files) so that they render at the appropriate physical size on each device. For example, if your application provides bitmap drawables only for the baseline, medium screen density (mdpi), then the system scales them up when on a high-density screen, and scales them down when on a low-density screen. This scaling can cause artifacts in the bitmaps. To ensure your bitmaps look their best, you should include alternative versions at different resolutions for different screen densities.
And from a Roman Nurik post
I talk about some of the key aspects of Android 4.4 KitKat that all Android designers should be aware of. Specifically:... 7) The introduction of new XXXHDPI (640dpi) launcher icon assets due to the Nexus 5 launcher's icon scaling behavior.
So it seems that it will scale, and that the resolution xxxhdpi is a newer implementation. I really would avoid using xxxhdpi images in an application unless you plan on using them specifically and for a good reason as they are going to be large files.
Edit
It does seem xxxhdpi was introduced in 4.3, as stated in this Android Police Article. Either way, it hasn't been around for long and isn't used by many devices at this point, so I still say that unless you have an explicit reason to use a xxxhdpi image it isn't worth the space and scaling issues you might encounter by using it.
It was first spotted in the 4.3 source (see Android Police) and its distribution is currently less than 0.1% (see Screen Sizes and Densities). Although the images would scale down you should include lower resolutions (I would go with mdpi, hdpi and xhdpi without xxxhdpi) to ensure both high image quality and high performance.

About Android resources and screen densities

I am developing android apps for years now, and I always struggled with the part of resizing all icons for all different screen densities.
A couple of days ago I developed a utility for making this task easy and released it's source. But I received the following comment:
"If you have a mdpi device, and an app only has xhdpi resources, the system will scale the xhdpi resources down to mdpi size automatically."
So, I should not create all icons in different sizes for all screen densities??? Have I been wasting effort and time all this years?
By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and Nine-Patch drawables (.9.png files) so that they render at the appropriate physical size on each device.
http://developer.android.com/guide/practices/screens_support.html
But you did not wast effort and time because to ensure your bitmaps look their best, you should include alternative versions at different resolutions for different screen densities.
Also this will give better performance

Apk size supporting multiple screen densities in Android

I'm developing an Android app which supports the following densities: ldpi, mdpi, hdpi and xhdpi. I have my images stored in each folder and scaled up according to the density. My problem is my APK size is about 100 MB, I guess the images of the four resource folders are adding up.
Is there any way to reduce this APK file size? When I tried to upload my app for testing in-app billing, Google Play has a limit of a 50 MB APK, so can't upload.
Why do users need to download APK which has images that they will never use from another resource foler? Any idea?
Why don't you use expansion file? Or try to compress data.
In September 2015 the maximum limit on the Play Store has been increased to 100 MB, if you need more space you can add up to two 2 GB expansion files but it's a bit tricky to implement.
Starting July 2016, when you upload an app, Google Play downloads only the part of the APK which has changed, reducing data consumption.
If you think that your problem is caused by the resources, why not to check the size of the drawable-<density> folders, just to have the exact idea of how much space every density is taking?
In any case, if you include only the low-resolution resources, on high-resolution devices they will be scaled up appearing blurry, while if you include only high-resolution resources, they will be scaled down on low-resolution devices, increasing the risk of OutOfMemoryErrors at runtime. In your case a good approach can be to include only the mdpi and xhdpi resouces: ldpi will then be scaled from mdpi, and hdpi from xhdpi.
Also check if you can replace some of your resources with 9-patches or, even better, with SVGs.
The last solution is to provide different APK for different densities (and screen sizes), as documented here.

Restricting apk size - Even with large number of resources?

I've used the following as my research :
http://developer.android.com/guide/practices/screens_support.html
Too large APK due to multiple densities and screens sizes?
How to reduce App (.apk) Size
I'm currently working on getting my application to support multiple screen sizes. At the moment I don't have the following in place:
Separate layout files for different screen sizes
Separate images in the relevant image-density folders (ldpi, mdpi, hdpi, xhdpi).
Other info:
All images are .png
I do want to support large screen sizes like tablets
I do not wish to support anything below this size - 320x480
Even though I don't have everything in place yet, my app is highly customized(in terms of graphics) - and is now a little over 4 mb.(.apk size)
If I do add separate layout files, and images - the app .apk file size will probably explode.
Question:
How can I get around this and keep the .apk file size to a minimum?
Idea's I've come up with so far:
Bitmap sampling - and creating an image loader
Downloading images from the net - I wish to avoid doing this unless there's no other option.
Converting some files to .jpeg files - Still a little unclear on how that works.
Using .9.patch image files? I believe this makes layout design easier.. but not sure if I could use that to save on .apk size
You can enable ProGuard in release mode. The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names. The result is a smaller sized .apk file that is more difficult to reverse engineer.
http://developer.android.com/tools/help/proguard.html.
Also have a look at the video in the link
http://www.youtube.com/watch?v=amZM8oZBgfk. The talk is about multiversioning.
Tips for reducing .apk file size
http://developer.sonymobile.com/2012/01/31/tips-for-reducing-apk-file-size/

How android drawable automatically change?

I have a android application, that uses many images. and application is to be used on different resolutions. I am using only one set of images and images are saved in "drawable-mdpi".
So "The images gets blur when I run it on a high resolution".
So probably the solution of this is to save different images of different resolution in drawable-hdpi,ldpi etc.
Is doing this is enough or do I have to change the images by code? or phone automatically adjust the perfact image into the drawables.
can anybody provide a example??
If you put the images in the ldpi,mdpi,hdpi or xhdpi folders Android chooses the images according to the current device dpi.
If you only add mdpi ressources and load them on a hdpi device Android will enlarge the images with a factor of 1.5 if you open them on a ldpi device they will be shrunk with a factor of 0.75.
The scaling is applied so that the images have (almost) the same physical size all displays with any dpi.
You should add different images for each dpi if those images will be blurry (or loose details when shrinked) after this autoscaling. If you have simple images that look well after scaling you only need to add one image to any dpi folder.
EDIT:
On Android there is no default way for automatically selecting images depending on the screen resolution. As the docs says:
When adding support for multiple screens, applications do not work directly with resolution; applications should be concerned only with screen size and density, as specified by the generalized size and density groups.
(see Supporting multiple screens).
This is enough. This is the reason for having different folders in the drawable directory, but note that Android 1.5 supports only 1 folder called drawable with no subdirectories (but there are no phones on 1.5 with resolution higher than mdpi)
One of the best ways of making sure your images are always properly scaled is to use 9 Patch drawables. Android will scale these according to the screen size automatically. They are best used for things that usually change size (Buttons, EditTexts, Spinners, etc), but can be applied properly in the right setting.
One advantage using 9 Patch images gives us is space-saving; having three different versions of images built into our applications can get quite large after awhile, but with 9 Patches you only need one copy.
See here for more details:
http://developer.android.com/guide/developing/tools/draw9patch.html

Categories

Resources