R.java 中的参考不是最终版本

2023-12-22

生成样式属性的引用时,R.java 文件的生成似乎出现了问题。

人们期望该字段的声明是final但事实并非如此。怎么会?

资源/值/attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="MyTextView">
        <attr name="typeface" format="string"/>
    </declare-styleable>
</resources>

gen/com.example/R.java

    /**
      <p>This symbol is the offset where the {@link com.example.R.attr#typeface}
      attribute's value can be found in the {@link #MyTextView} array.
      <p>Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.
      <p>This may also be a reference to a resource (in the form "<code>@[<i>package</i>: <i>type</i>:<i>name</i></code>") or theme attribute (in the form "<code>?[<i>package</i>: [<i>type</i>:]<i>name</i></code>") containing a value of this type. 
       @attr name com.example:typeface
    */
    public static int MyTextView_typeface = 0;

自几年前以来,R.java 中的参考文献都不是最终版本。

原因是,如果您的主项目依赖于多个库项目,则生成的 id 可能会发生冲突。

这是对此的更多解释:http://tools.android.com/tips/non-constant-fields http://tools.android.com/tips/non-constant-fields

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

R.java 中的参考不是最终版本 的相关文章

随机推荐