So I am not such a newbie in Programming, Java or Android developing, but I got a strange issue: I have made an application, quite advanced, and have it on market.
For now I have over 1000 installs and I have around 4 or 5 crash reports for a ResourceNotFoundException. The strangest thing is that the line it crashes on is on
setContentView(R.layout.some_custom_layout)
In code I am always referring to resourced by
someTxtView.setText(R.string.some_string)
So I am wondering if I used
mContext.getResources().getDrawable(mContext.getResources().getIdentifier("some_string", "string", "my.example.package"));
would the crash go away?
I was facing the same issue and I fixed it by creating Layout Folder called "layout-small".
Based on resolutions I have created only 2 folders "layout-large" and "layout-medium". But few phones are having lower resolution it doesn't find proper resources as per the resolution. Android OS renders xml resources as per resolution. It goes and find the resources in required folders.
95+ % Android phones having resolution which matches "layout-normal" folder. But still there are Phones having lower resolution. Hence this issue occurred.
For more Details : http://developer.android.com/guide/practices/screens_support.html
Hope this helps your problem.
If you are calling setContentView(R.layout.some_custom_layout) from the Activity's onCreate method, you should be good as long as your app compiles (and I assume it does).
AFAIK accessing your string resources via:
someTxtView.setText(R.string.some_string)
is not the way to go. You should be doing this:
getContext().getResources().getString(R.string.some_string)
Except
setContentView(R.layout.some_custom_layout);
try using
setContentView(yourpackagename.R.layout.some_custom_layout);
that helped me a lot of times.
I have one suggestion. Do you use in your layouts android secific resources, such as drawables or something, for example
android:backgroud="#android:drawable/some_android_drawable"
Maybe some vendors don't provide some resources with their firmware, so your app crashs.
for example this issue
someTxtView.setText(R.string.some_string)
There you set integer value to text. Its not correctly becouse it search a resousre on this value. You must write
someTextView.setText(getResources().getText(R.string.blabla));
Related
I am getting duplicate files in my source code:
This happens quite often with Android Studio and it happens will all types of files, not just gradle files. It typically happens when I checkout a new branch or swith branches.
What is causing this and how can I prevent it?
As a note, this question was originally posted with image files, thus the image answers. However, this is not limited to image files and I understand why there are multiple image files for different screen densities. I have updated to reflect that there are other files being duplicated.
Do you have a Mac, and is your project stored in your "Documents" directory?
Filenames that include " 2" are generated by iCloud when it can't reconcile two versions of a file. E.g. if you have two computers, and both of them share their "Documents" directories via iCloud, and a file were to be changed simultaneously on both computers, iCloud would wind up creating e.g. a build 2.gradle file.
I found this was happening to me, even though I'm only using one computer to do my work. I suspect that Android Studio may be interacting with iCloud directly, not realizing that it's working on files that are already backed up on iCloud. (See Android Studio generating hundreds of duplicate " 2" files).
I seem to have fixed it by moving my project directory out of Documents. At any rate, I haven't had a problem since I did that.
(Credit to Mike M. for noticing the similarity between our problems.)
Since different devices support different screen densities, all non-vector image drawables should have an image asset for each type of density. So, from a development standpoint, you're using the same Drawable but the app will use the correct image size based on the screen density of the device the app is installed in. I suggest you take a look at this article for more information.
It's ok. Follow the every folder. Folder name is different according to possible phone size Different phone size is different, that’s why they support different size images.
I used Locale.getDefault.getDisplayLanauge() to get language code, but I get "hd". I don't know what's it. I suppose it should be "en".
Could someone give me a hint why it's "hd" by default, and what does it mean?
I had the same problem. Are you making your own Android build?
It's happening, when you use the screen density as first argument of PRODUCT_LOCALES. In my product mk file the first argument of PRODUCT_LOCALES was hdpi. I moved it to the end and now everything is working fine.
You probably have the exact same problem as I had. The Android build process takes the first two letters of the first word in PRODUCT_LOCALES and stores them as default language. And if you have, like I had, hdpi Android takes "hd" as default language!
Also I found this comment in a Android makefile, which explains this problem perfectly:
Screen density is actually considered a locale (since it is taken into account
the the build-time selection of resources). The product definitions including
this file must pay attention to the fact that the first entry in the final
PRODUCT_LOCALES expansion must not be a density.
I'm planning to use the Multiple apk approach to my current project, since it has a big number of drawables for every density and the apk file is big right now. Are there any pitfalls in using this kind of approach? By the way, does the download statistics "sum up" on the Android Market for Multiple apk's? Thanks in advance.
As our comment discussion
In my experience apk size does not affect performance of application.As if you are using hdpi
device then ldpi resource will not load.So device will load only the resource required by
current device.And i think this is best approach.
Second If you want to make three application instead of one for ldpi,hdpi,and mdpi then its very time consuming.and it cannot sum the download of all three application.Android gave three option of ldpi,hdpi,mdpi.So we have to use it.
Hope you got my point
Hi my customer tried to add the apk to their market application and an error occured like below.
*18.Ağu.2011 12:23:14 brut.androlib.res.AndrolibResources loadMainPkg INFO: Loading resource table... Exception in thread "main" java.lang.Error: Androlib Error: Multiple resources: spec=0x7f02004c drawable/top_bar_large, config=-ldpi*
it seems the tool thinks that the drawable resource named top_bar_large has been used more than once. That's right but in different drawable directories.
I mean the image is located in the directories;
drawable-ldpi
drawable-xlarge-ldpi
As I know android handles this automatically. And I also have installed that failing (actually the tool thinks it is failing) apk to my phones and other phones ( different brand ) without any issue !
What do I need to do ? can you help me ?
I hope this is still relevant.
I would suggest one of two things. First, try the latest version of apktool. As far as I know, xlarge was added rather late to apktool. The latest version should work fine.
If not, you can try zzos (full disclosure: zzos was written by me). It is much less known, but may occasionally be able to handle APKs that apktool fails to decompile. In particular, I happen to know that xscale is supported by zzos, and has been for some time.
I hope this helps,
Shachar
I'm developing an android app, I'm testing with samsung galaxy tab, for any reason my xxx_layout.xml is not working, it remains in its first version, if I modify it none of this changes are viewed, I make all the process to generate an signed apk, clear any data in the tablet before install but this problem still appearing.
Please any sugestion or solution is welcome, thanks
Greetings
Do you have another definition that is ovrriding this one?
Files in res/layout/ are "defaults" or fallback versions that are used when no better one is found. Now on a tablet,with a hdpi or xlarge screen, layouts in res/layout-hdpi or res/layout-xlarge are taken before the ones in res/layout.
can you make sure that this layout file is actually used.
also check if you have any errors in the layout file.