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/
Related
I'm making an Android app in Android Studio and was wondering if I import a SVG file will it be scaled down or up to fit every screen?
For example it looks good on my S20FE which is XXXHDPI screen, but will it look the same on say HDPI screen without making separate XML Density files
Edit: I do not have any device with smaller density and for some reason a virtual phone that can be run in Android Studio doesn't work for me.
According to https://developer.android.com/studio/write/vector-asset-studio , "Using vector drawables instead of bitmaps reduces the size of your APK because the same file can be resized for different screen densities without loss of image quality."
So, same SVG will be scaled depending upon the screen size.
SVG files are best because they will reduce the size of APK and quality is best. if you do not know how to use SVG files then please ask me. I will provide you step with step process.1 SVG file works for every device without quality change so you do not have to make separate 5 file for every resource.
Need to build an android apk less than 20kb, and rest of the contents in the app should download dynamically, does anyone have idea about that.
If i create a simple android app and build it without any source code, it results in 3 MB atleast.
So, so pls someone suggest me how can we create an apk in kb.
I decided this would be a fun challenge, and was able to make a tiny app (no real functionality) that was 16kb. You can find the source code here. It would have been even smaller with only ldpi assets.
Some caveats:
Don't expect an app with any real functionality to come in this small. Keep in mind that 20kb is around 20,000 characters worth of data, which would be about the length of a very short story. 20kb really isn't realistic, and you are going to end up taking up that extra space on your user's phone when you download the "rest of the app" later anyway.
My example has only mdpi assets. Things like launcher icons have to be bundled with your application, so either your icon will look awful on large devices, or you need to modify your requirements.
Some tips:
Enable proguard. Both minification and obfuscation. The latter is a hyper-optimization, but when you are trying to go that small, every bit helps.
Take out any libraries that aren't absolutely mission critical. You aren't going to make it with any of the support library.
Support only the lowest resolution screens you can. ldpi assets will look bad on high density screens, but are exponentially smaller than mdpi, which is exponentially smaller than hdpi, etc. Resources are almost guaranteed to be the largest piece of the app.
Read all of the Shrink Your Code documentation. One great tip if you are using any libraries that provide resources is to use resConfigs to strip out any languages, densities, and native ABIs that you don't need.
Android Studio 3.0 has an "analyze APK" feature that will break down what pieces of the APK are taking up the most space- use that to identify your targets for cutting down the size.
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.
I've read "Supporting Multiple Screens" on the official docs.
I have around 15 activities. I currently have 4 background images. I've randomly assigned a background image to each of the screens in simple XML.
All these images are around 400X800 in the drawable hdpi folder.
Now the problem:
My app looks bad on tablets. The low resolution images are stretched out.. making them very blurry. So, I'm thinking about adding some higher res images.
The question:
So, now I have 4 images in the hdpi folder. (read slowly) ... If I add the same images of higher resolution in the xhdpi folder .... Will a device with screen of hdpi resolution also have to save the other res pics ?
I know that was confusing, below I explain with an example:
Okay, so I have three devices..
One small,
One medium,
One Tablet.
Now I have 3 sets of images in the mdpi, hdpi and xxhdpi.... for each of these.
Now, will the small device's apk file also contain the bigger images which are not used in it? ... I mean, can android choose which images it wants to download (changing the app size for different devices) ...?
Or does it simply download everything (increasing the app size)... and choose later on while running ?
The thing is, my app is like 800kb .... and adding 3-4 background images for large phones or tablets will drive up the app size to 5-6 mb... That's what I don't want.
So, are all the things stuffed in the apk downloaded equally on all phone sizes ? or are the pics downloaded selectively?
Do small phones unnecessarily download the big images too ?(vice-versa for tablets ?)
(I asked this question, because in many android apps , their size says "Variable for different devices" or something like that... and there's no mention of this whatsover, anywhere on the internet. Trust me, I googled for an hour.)
Yes. Your project size will increases whatever images added in all folders. If you are designing for 4 different screen your apk size will increase automatically. If you want any images common for all screens, then you can create a drawable folder and place the image in it. So it will pick automatically. Both apk size and your project quality are important. So you should consider image size when adding to the project. By using padding and other xml factors you can adjust screen size by same image also.
The whole apk is downloaded together with all images for all resolutions. As you usually upload only one file to Google Play, the same file is downloaded by everyone.
There is an option do distribute different apk files based on device onfiguration but it is not very convenient to manage.
You can read about publishing multiple apk in here: http://developer.android.com/google/play/publishing/multiple-apks.html
On my android project I have 5 kind ok drawable: xxhpdi, xhpid, hpdi, mpdi et lpdi
But I don't realy understand in witch file set my images
I had a look to this link: http://developer.android.com/guide/practices/screens_support.html
I need to class my pictures by size and by px/in
I have ic_launcher in my folders:
xxhpdi => 144*144px
xhpdi => 96*96px
hpdi => 72*72px
mpdi => 48*48px
lpdi => vide
But they are all in 72*72 px/in
I'd like to know how to set my pictures in res folders, why not just have a xxhpdi image ?
and did we always need to have 5 image, it weighed the application.
Thanks
Resolutions were explained in other answers. Regarding the question about weight of the app, You could provide different apks for different devices via Android Market, so particular apk would include only images for particular screen.
Moreover, the same time You don't need to do simultaneous development of many branches etc. just because of images differences, just follow Android documentation on support multiple screens and produce separate builds using aapt -c key which would allow You to have only necessary configuration included in every build..
The Android system will choose the closest 'density bucket' (drawable folder) to the current device, and use that for some final resizing to the devices exact size.
Its a guideline to provide an image for every density bucket to ensure the best result, but in practice often an image will look just fine by only adding it in 1 or 2 folders.
If you have a problem with having some big images that make your app huge, cause you have to add them 5 times, you could try around with adding those only in 1 or 2 folders.
Per example, xxhdpi is only nexus 10 at the moment, are you even really supporting that? ldpi is also not very common anymore. You could try adding it only in xhdpi, and scaling will probably look fine.
For the rest your images shouldn't be much more than some simple icons, which shouldn't take up a lot of space.
tl;dr: Yes if you want to follow guidelines for best result, but you can probably cut on app size without people actually noticing.
Android comes different screen resolutions, each resolution depends on screen width/height.For mobiles you place the corresponding sized images in res folder. During run time device itself find the resolution and re size the resolution it needs. For some cases you may get issues like image squeeze etc. At these time you place the corresponding image sizes with their corresponding res folder with same names.
I wrote a little toole for this.(BitmapCat) It scaled png-, bmp-, and jpg images for Android apps in:
ldpi(low-density)
mdpi(medium-density)
hdpi(high-density)
xhdpi(extra-high-density)
xxhdpi(extra-extra-high-density)
Here you can download it: http://blog.axxg.de/bitmapcat-en/