In Android Studio 2.2.2 I have an error in AndroidManifest.xml file saying
Resources referenced from the manifest cannot vary by configuration
There is a StackOverflow question by someone else on this message but the answer only describes how to ignore it. What I want to know is what does it mean?
The line associated with the error says
android:versionName="#string/appvername"
what does the error mean and how do I prevent (not just ignore) it? What is a "configuration" in this context?
What is a "configuration" in this context?
Quoting the documentation:
You should always externalize resources such as images and strings from your application code, so that you can maintain them independently. Externalizing your resources also allows you to provide alternative resources that support specific device configurations such as different languages or screen sizes, which becomes increasingly important as more Android-powered devices become available with different configurations. In order to provide compatibility with different configurations, you must organize resources in your project's res/ directory, using various sub-directories that group resources by type and configuration.
So, a configuration is a mix of device capabilities and states that controls what resources get loaded. For example, the device locale settings determine which strings get used from your available string resources.
What I want to know is what does it mean?
Not every attribute in the manifest can be populated by a resource, because the system cannot handle varying values based on configuration.
For example, you cannot change the Java class name of an <activity> by using a string resource in android:name, with an eye towards using different Java classes with different screen sizes. While that's an interesting concept, Android is not set up to support that.
how do I prevent (not just ignore) it?
In this case, I think you are encountering an IDE bug. android:versionName should support string resources, as that is a user-facing value, and therefore you might want to translate the string. So, add tools:ignore="ManifestResource" to the <manifest> element, until the bug gets fixed.
Related
From the documentation: "The Android SDK tools compile your application's resources into the application binary at build time.". So it's safe to assume that all Resource ids will be the same, no matter which device is running them?
Yes, the constant values will be the same.
However, I'm not sure how this information is useful in any meaningful way. The values can change from one build to another, e.g. when you're modifying your resources and then re-building the app. Using the value to communicate something outside the app is therefore fragile.
No you can't trust the R file that could change if you have such a case you should better set a Tag with your view and use it. Well that is not recommended.
However this is not a logical question still i am much interested to know if i have any idle file that i am not using in my project.Sometime after a long project we just dont recognize that which is the actual file and which is the copy of it.Sometime we just create some xml files to check the layout and other effects like selector or some custom drawable.I mean though these file never be get executed still it crates logical confusion when we get back to our code about true identity and use of the file.
I read that Proguard removes all unused files before making apk file.Does it remove all these xml files also ?
I am bit new about proguard concept.
Thanks.
You can use AndroidLint, tool who scan your project and return a lot of advices, and then, all unused resources !
http://tools.android.com/tips/lint
- Missing translations (and unused translations)
- Layout performance problems (all the issues the old layoutopt tool used to find, and more)
- Unused resources
- Inconsistent array sizes (when arrays are defined in multiple configurations)
- Accessibility and internationalization problems (hardcoded strings, missing contentDescription, etc)
- Icon problems (like missing densities, duplicate icons, wrong sizes, etc)
- Usability problems (like not specifying an input type on a text field)
- Manifest errors
For some time we have been receiving weird android.content.res.Resources$NotFoundException exception from our production application (via Play store).
The error commonly appears while trying to access to string resources declared in res/values.
To give a concrete example, in our Application subclass, we load a string ressources in onCreate() method (so at any app launch).
The string resource actually exists in res/values and the production application works fine on all our test devices so it cannot comes from a wrong generation of the R file.
We guessed it came from the fact the the values weren't redefined in other values package (like values-hdpi or other packages) and copying the string values into all packages actually stopped the exceptions.
Still, according to the Android documentation, if no specific values are found, the values of the default package are taken by default so we don't understand why this error occurs.
We are thinking it might be custom roms that don't operate 'normally' so I wanted to know if other people had the same issues or anyone had other suggestions.
There are so many Android devices with different configurations. So when we don't keep resources specific to corresponding matching device configuration[drawable-hdpi,values-en,layout-land etc] then android system looks into default configurations for that resource[drawable,values & layout].
So recommending to keep both default & configuration specific resources in respective locations.
I have on this moment too many xml string values. I started to delete the ones I don’t use, but this is quite hard (I don’t really know which I do use, and witch I don’t). Is there a function in eclipse that can do this for me, or help me whit it? (Like some call hierarchy)
Android Lint should be able to help you with this.
On the website it states that it can do following things:
Missing translations (and unused translations)
Layout performance problems (all the issues the old layoutopt tool used to find, and more)
Unused resources
Inconsistent array sizes (when arrays are defined in multiple configurations)
Accessibility and internationalization problems (hardcoded strings, missing contentDescription, etc)
Icon problems (like missing densities, duplicate icons, wrong sizes, etc)
Usability problems (like not specifying an input type on a text field)
Manifest errors
What does the translatable attribute, like translatable="false", mean?
This attribute points out that this attribute will be the same for all locales. Why is it useful?
The localization files are more readable for human and saves time.
It tells the Lint tool that everything is fine and that Android does not need to look for this resource translation.
Full explanation:
http://tools.android.com/recent/non-translatablestrings
So, generally, this means if don't put this attribute, you should always localize this resource, otherwise tell people and compiler that this is unique for all locales by specifying this attribute.
If you are supporting multiple languages, and there are some strings which should not be translated (that means same across all languages) then you can use translatable="false"
For ex: Numbers<string name="account_setup_imap" translatable="false">IMAP</string>
Detailed Description
I've never heard of that attribute, but apparently (now) there's a reason for using it: see this post from ADT-Dev google group.
BTW, I just tried it and it works in fixing those Android Lint errors.
I don't see any reference to that in official docs, however, it probably is just an indicator for humans looking at the file that that particular string entity should not be translated.
If you have an Android app that you wish to internationalize, a common tactic is to just send your strings.xml file to translators. So that attribute would just be a flag for them.