user316117 user316117 - 1 year ago 69
Android Question

What does "resource varying by configuration" error mean?

In Android Studio 2.2.2 I have an error in

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


what does the error mean and how do I prevent (not just ignore) it? What is a "configuration" in this context?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download