我出于好奇而创建了一个简单的Android项目。它包含两个模块:app
和lib
。每个模块都有其自己的包名称。我在lib模块中创建了一个字符串资源,在app模块中创建了一个字符串资源。像这样:
<string name="my_str">my_str_from_lib</string>
<string name="my_str">my_str_from_app</string>
然后我在应用程序模块中将文本设置为两个TextView
:
fromLib.text = resources.getString(ru.maksim.sample.lib1.R.string.my_str) // here I expected to see the string from the lib.
fromApp.text = resources.getString(R.string.my_str)
在两种情况下均为my_str_from_
app我运行Lint并认为它将检测到资源覆盖的事实。但事实并非如此。有机会发现这种情况吗?不一定与Lint有关。其他工具也适合我。
您可以在根文件夹中进行全局搜索。查找my_str的所有实例,并确保仅使用它作为名称的应用程序中的string.xml。