Android hdpi resource load problem - android

good day
we are developing game for android and have some trouble with resource loading on high dpi devices.
our resources are located in res/drawable directory
on a standart dpi device the game work properly, but on hdpi (tested on HTC Desire) all resources which located in res/drawable-hdpi load are loaded correctly, but the resources which miss in drawable-hdpi directory but present in res/drawable are ignored
but everything works fine on the virtual device with hdpi.
does anybody encounter this problem and know how to solve it?

Well from non device tester advice here, can You move those missing resources to drawable/nodpi if that does not conflicts your development strategy ?
Don't know to what extent it will work, but u can try!

Related

Resources not found, but only on seemingly random devices

I'm getting quite a few crashes on a live app.
Fatal Exception: android.content.res.Resources$NotFoundException
Resource ID #0x7f080389
The resource exists.
It is a PNG and it's set using.
icon.setImageResource(a.icon);
where a.icon is an int with the id of the image required. I'm 100% sure the value here is fine.
There is no obvious pattern in regard to device and operating system. With the same phone and os version in testing and most live users everything is fine.
The app is distributed on Play Store using a package.
My current theory is that some people are getting the app via some other place (the app is not available everywhere) and the APK they are trying to use does not match the screen density of their phone.
Is this reasonable (and can I prevent this) or is there another possibility?
Cheers.
This exception is coming because image is present but not for all the resolutions.
Device will check the image in all the drawable folders which are equal or lesser resolution to resolution of current device.
Various screen resolutions are mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi.
Example: if you image is present in drawable-xxhdpi folder and device is of resolution xhdpi. Then it will check for image only in drawable-xhdpi, drawable-hdpi, drawable-mdpi and default drawable folder and may result to resource not found exception.
Hence you should add image to all the various resolution folders as per the quality. xxxhdpi should have sharp and high quality images.
Also, it is recommended to add default images in the default drawable folder to avoid any resource not found exceptions.
Hope it helps.
Released the app as an APK. No issues at all. Definitely something not quite right with the package splitting.

What's preventing Android from finding a resource file in drawable?

I'm working on a bug of my Android application and it only occurs on a Galaxy Nexus with Android version 4.2.2, but works fine on my Nexus 5 with 4.4.2.
Basically it's not able to find a png file on this device.
The png file is only located in res/drawable and here is the structure of my res folder:
res/drawable
res/drawable-de
res/drawable-fr
res/drawable-it
res/drawable-hdpi
res/drawable-ldpi
res/drawable-mdpi
res/drawable-xhdpi
res/drawable-xxhdpi
What could be preventing Android to fallback to the drawable folder in this case?
Without knowing anything about the image its hard to say, but the image may be too large. Alternatively, unless there's a compelling reason not to, you should probably put it in a *dpi folder anyway
What is the configuration of your device when the drawable resource couldn't be found? When the device language is German, it might happen that one of the resource directory, e.g res/drawable-de has taken precedence of the drawable directory.
Take a look at here how android find the best matching resources.

App crash on devices with ldpi screens

I created an app with images, and I added them via Android Icon Set wizard. The wizard created 3 versions for the images - mdpi, hdpi, xhdpi.
I published my app on google play, and I got a crash reports from users that have ldpi screen. The exception was Caused by: android.content.res.Resources$NotFoundException: File from drawable resource ID #0x7f02007f.
The drawable was exists in mdpi, hdpi and xhdpi and the app worked to the rest of the users.
So I guess that the problem was that the drawable dose not exists in its ldpi version.
So my questions are:
1) Is there any way to say to the app to auto scale the mdpi drawables instead of crashing?
2) For support ldpi screens, must I edit the images to ldpi size?
Thanks.
This is a common error of different densities management, so these are the answers to your questions.
1.- No, in the way your assets are stored but Yes, "ONLY if your asset is in a lower hierarchy of your current density" for example: If you have assets in drawable(default non specific density) and drawable-ldpi AND you run the app in a Medium Density Device, the OS will try to resize your Images from -ldpi to your density (if using dps in the Image but will cost memory). The way the OS handles the Assets is the following:
Lets say you have:
res-
-drawable
-icon.png
-drawable-ldpi
-icon.png
-drawable-mdpi
-icon.png
If you are running an app in a HIGH Density device the OS first will try to find your asset in drawable-hdpi, but since it doesn't exist it will start going down the hierarchy until it finds it, so in this case it will not find it in drawable-hdpi but will find it in drawable-mdpi and will use that one to populate, everything will be fine but will cost in memory the difference of densities in the assets.
Now the exact error you have comes to play when the OS goes down the assets folder hierarchy and goes until the end and do not find anything for example:
Lets say you have:
res-
-drawable-hdpi
-icon.png
If you run this app, in HIGH Desnity Device it will run perfect, because will find the asset in the first try and will never go down the hierarchy, same case for Extra High Density Device because if it doesnt find it in drawable-xhdpi it will find it in the next step when going down the hierarchy to drawable-hdpi and will work just fine, but for MEDIUM Density, however, first it will try to find it in drawable-mdpi since its not there, will go down and try to find it in drawable-ldpi no luck either so it will go to the "default (drawable)" which is a good practice to contain all the assets in an average size to at least make the app look blurry than crashing, since the OS will not find the Asset either BOOOM no resource found, there you have your exception, this mechanism applies for pretty much any resource in Android
2.- YES, you must create your assets in ldpi and store them either in drawable-ldpi or drawable(default - no density) in order to make it look good.
All this information has been taken out of a book and if you still have doubts, create an empty Android Project in Eclipse and notice how the SDK creates one icon_launcher.png img in each density with a specific size to handle exactly this issue. As a recommendation in my experience I've found useful to always take care of all the densities, but more important having all my assets with an average density/quality in the default folder to avoid this exact issue in case you could forget one density during development, is better a blurry asset than a crash.
Hope this Helps.
Regards!
Is there any way to say to the app to auto scale the mdpi drawables instead of crashing?
This happens automatically, unless the maker of the firmware (device manufacturer or ROM modder) screwed it up.
For support ldpi screens, must I edit the images to ldpi size?
No.
I would look up 7f02007f in the R.java associated with your production code base and make sure that it is what you think it is. Bear in mind that these numbers get regenerated on every compile. Perhaps this is a case where there simply is no drawable resource for this number, in any density, because R.java was out of sync with the actual resource packaging. To avoid this problem, do a clean build (e.g., Project > Clean inside of Eclipse) as part of making the production APK.

android app icon missing on certain device

I've recently developed an Android app. For some reason the app icon does not show on the home screen on a HTC One device. The icon shows fine for my other devices.
Reading other forums, I have made sure the app is stored within the phone rather than the SD card, and tried rebooting but these do not seem to fix the issue.
I'm guessing that the HTC One is not picking up the icon file, but I'm not sure why - as the other devices including Galaxsy S3 and other HTC devices do? Any help would be appreciated.
Thanks in advance!
I suppose you've created folders to support various densities? ldpi,mdpi,hdpi,xhdpi? If that's the case, are you sure you've put your icon in XHDPI folder because HTC ONE will read it from there because it has very big density.
For example:
According to GSM Arena, Galaxy S3 Galaxy S3 has 306ppi pixel density. That's high density and this phone will read drawables from hdpi folder.
On the other hand, HTC ONE has 469ppi pixel density. That's extra large density and this phone will read drawables from x-hdpi folder. GSM Arena, HTC ONE
But this may not be the case, because if drawable is missing from one folder will just read it from another available. But please check again your x large folder.

Resources$NotFoundException drawable-xhdpi from drawable resource

I was checking my bug reports and from time to time we get this bug report from our app.
I can't pint point what is the actual problem.
This resource does exist, most of devices work fine but some specific devices like LG-E510 or U8815 just cant load this resource.
Any ideas?
android.content.res.Resources$NotFoundException: File res/drawable-xhdpi/action_bar_search_icon.png from drawable resource ID #0x7f02007f
at android.content.res.Resources.loadDrawable(Resources.java:1714)
at android.content.res.Resources.getDrawable(Resources.java:581)
at com.actionbarsherlock.internal.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:384)
at com.actionbarsherlock.internal.view.menu.ActionMenuItemView.initialize(ActionMenuItemView.java:128)
at com.actionbarsherlock.internal.view.menu.ActionMenuPresenter.bindItemView(ActionMenuPresenter.java:192)
at com.actionbarsherlock.internal.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:176)
at com.actionbarsherlock.internal.view.menu.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:178)
As you have stated, if the phone / tab accesses the xhdpi directory then we expect it to scale the image appropriately to fit the screen. Therefore we expect that if the resource exists in ANY ONE of the directories then we will never see a ResourceNotFound exception. HOWEVER:
xhdpi was only introduced in Android SDK 8, so if you target SDK 7 and earlier you may run into problems:
Only use XHDPI drawables in Android app?
Another reason why Android may not be able to access the xhdpi directory is if the device is running in screen compatability mode:
Android - Extra large images placed in res/drawable-xhdpi aren't showing on tablet emulator, why?
Another possible reason is if your drawable is very small and one of its dimensions is rounded to zero as a result of scaling:
Android resource not found because of width and height
Finally, it is possible that some OEM versions of Android may implement this in a non-standard way (e.g "enhancing performance" by not searching the xhdpi directory if their device is hdpi):
Android Drawable hdpi xhdpi mdpi ldpi concept
You should keep your drawables in the hdpi folder. Since the phones that it doesn't work on have less pixels, they can't show the image. Just relocate the files.
Edit: They have less pixels because they have a smaller screen size.

Categories

Resources