android - "resource varying by configuration"错误是什么意思?

标签 android android-studio

在 Android Studio 2.2.2 中,我在 AndroidManifest.xml 文件中有一个错误

Resources referenced from the manifest cannot vary by configuration

有一个StackOverflow question其他人对此消息的回答,但答案仅描述了如何忽略它。我想知道的是这是什么意思?

与错误相关的行说

android:versionName="@string/appvername"

错误是什么意思,我该如何防止(而不是忽略)它?在这种情况下,什么是“配置”?

最佳答案

What is a "configuration" in this context?

引用 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.

因此,配置是设备功能和控制加载哪些资源的状态的组合。例如,设备区域设置决定了从可用字符串资源中使用哪些字符串。

What I want to know is what does it mean?

并非 list 中的每个属性都可以由资源填充,因为系统无法根据配置处理不同的值。

例如,您不能更改 <activity> 的 Java 类名称通过使用 android:name 中的字符串资源,着眼于使用具有不同屏幕尺寸的不同 Java 类。虽然这是一个有趣的概念,但 Android 并未设置为支持该概念。

how do I prevent (not just ignore) it?

在这种情况下,我认为您遇到了 IDE 错误。 android:versionName应该支持字符串资源,因为这是一个面向用户的值,因此您可能想要翻译字符串。所以,添加 tools:ignore="ManifestResource"<manifest>元素,直到 the bug gets fixed .

关于android - "resource varying by configuration"错误是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40726505/

相关文章:

java - 动态设置textview的宽度

android - LeakCanary 没有提供足够的信息来识别泄漏

android - 在Android Market中强制 "update (manual)"

android - Android Studio 模拟器没有声音

java - 由 : android. view.InflateException : Binary XML file line #9: Error inflating class android. widget.ImageView 引起

Android - 判断某个InputMethod(自定义键盘)的调用应用

android - 添加大的 png 图像后 .SO 创建导致应用程序大小增加

android - Gradle同步问题错误:任务 ':app:mergeDebugResources'的执行失败

android-studio - FragmentBasics的Android培训不会导入AS 1.5.1

android - Gradle 依赖更新