I have moved all my images from the folder mipmap to drawable because here it was said that the mipmap folder is only for app icons to lanch the app Mipmaps vs. drawable folders (the answer got 841 likes). However, when I now want to start my app I get an error message
FATAL EXCEPTION: main
Process: com.example.td.barapp, PID: 4331
java.lang.RuntimeException: Canvas: trying to draw too large(188394348bytes) bitmap.
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
In several realted questions people tell to store the pictures in different drawable folders (see Android : Understanding drawable folder) like drawable-xxhdpi or drawable-xxxhdpi.
Update: I was told by someone in this post (who later deleted his answers) to store the image (which has a size of 1,7 MB) in the folder drawable-anydpi. I did as he said but the outcome on the Emulator looks quite bad for an imageview (see screenshot):
Then I moved the same file back into the folder mipmap-xxxhdpi and now it looks good again. So my question now is, whether it is also okay to have the image in the mipmap-xxxhdpi folder instead of the drawable folder? I'd be happy for every advice because I am quite confused now.
java.lang.RuntimeException: Canvas: trying to draw too
large(188394348bytes) bitmap
This exception mainly because you are trying to display a big image ~ 188MB which will have a high resolution, and android puts limitation on that, This also reported here.
One of the reasons is to save device resources; for instance you might get java.lang.OutOfMemory, so the system save device memory from that.
1, 2, 3 may guide you thoroughly on that.
Normally you can use a few mega bytes image in your app ~0-3MBs.
Third party libraries like Glide & Picasso offer disk, network, & memory management techniques while displaying images on your ImageViews.
One of the options you may consider is to resize images before loading them, so can have look on this question.
Keep in mind that android puts limitaion on your apk file on the app store, so you need to minimize images for that reason, or load them from a back-end server.
As you mentioned, you can only put app icons in res\mipmap. And if you decide to put the images on your app, it's efficient to create them in different densities (hdpi, xhdpi, xxhdpi, xxxhdpi...), so they can match all the variety of device resolutions, and lets you avoid distorted images or high processing by android OS to match your image to the device resolution before displaying them.
Related
I am about to publish an android application which uses several images with different resolutions. I have found the hard way (with a crash) that putting all images in drawable folder causes a OutOfMemory Exception because images are scaled up. By putting all images in a high dpi folder like drawable-xxhdpi the problem goes away.
My question is : should I arrange images according to their resolution to the respective folders ? Will that make any difference ? Will android scale-down an image found in drawable-xxhdpi even if it is a low resolution one ?
You may want to use Glide for rendering drawable in your app. Glide provides you mean to auto scale the images according to your image holder size. This also caches the images for faster access (if you were to use network images). Read the doc and see if it helps you.
Bare with as this is my first ever question.
I'm developing an Android application and I was ready for it to be reviewed by Google and uploaded to the Playstore. It's a simple book reading application which uses individual .png files as the pages to scroll between and I use a ViewPager to view them. I was unaware that Google had a limit on the app size that you can upload at 150mb. This is the error I am receiving
The original size of my drawables folder was 761mb. I have been able to convert it down significantly to 250mb however it is still 102mb over the limit. Minify is enabled. I have tried the Webp convert in Android Studio but it barely makes a difference. Using AAB also create more than a 10mb difference. Click for APK Aalyzer.
Anyone know anything else I can do? I've tried to convert over the images again but it doesn't make any difference to the size. I would want the images to be saved on the device rather than downloaded from the internet so that it can be viewed offline. I have looked into expansion apk's but all of the documentation points towards it only being saved in external storage.
Your solutions:
If you do not want to receive images from the server, try to reduce the size of your photos(compress) with the following two sites:
https://tinypng.com, https://tinyjpg.com
Convert your images to webp (in android studio right click on drawable image and click convert to webp)
Recommended use https://appicon.co/#image-sets to Get different sizes of your images ( mdpi, hdpi, xhdpi, xxhdpi , xxxhdpi )
If I create a blank new project and run it, it uses 23MB of memory.
If I add one 540x960 png image to the background of the layout, it uses 47MB of memory.
If I add an image button with a background image on it, it uses 64MB of memory.
This continues to go on if I add things, and this is way too much. On the app I am currently working on, I have memory used at between 180-210MB of memory. I figured there was something wrong I was doing with loading the images, so I ended up putting them all on imgur, and loading them in with Glide. This reduced the memory by a small amount, and also doesn't explain why a new blank project would use 23MB.
I thought there might be some kind of setting, but I re-installed with default settings and am still getting the problem.
I experienced a similar issue when I put the drawable in the wrong resolution folder, especially the standard "drawable" folder is a pitfall since it is assumed to contain the image in "mdpi" resolution, so the image gets upscaled like crazy on xxhdpi devices.
Here's a simple test to figure it out, move the images into a folder called "drawable-nodpi" and check for the memory consumption.
Then make sure to provide the image in the right resolution in their dedicated folders, and avoid the "drawable" folder for images, just use it for xml drawables.
What basically happens is if you put your "540x960" image in to the standard drawable folder, it is assumed to be mdpi, if you view it on a relatively modern "xxhdpi" devices the image gets upscaled by a factor of 3 e.g it will be "1620x2880" and therefore consume much more memory.
http://developer.android.com/guide/practices/screens_support.html
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
I am saving 4 copies of every image in my game, each with a different density. They are saved in the relevant res/drawable-* folder, and it seems to be working great on various devices.
So, currently, I open up photoshop, and have one psd for each image. I edit the vector's appropriately, change the density, and save the image in the appropriate folder. I have to do this 4 times, for every image. It takes forever, and I am trying to avoid getting sloppy and messing up one density of one image and not noticing it.
Is there a better way to this? When you have to create and edit your drawables over the course of development, how do you do this?
Check out batch processing in Photoshop. It will be the same thing you do, only automated
http://howto.wired.com/wiki/Batch_Process_Images_in_Photoshop