我有一个基本功能模块和一个功能模块(您可以称它为“子”)。基本功能模块具有一个包含以下内容的strings.xml文件资产:
<resources>
<string name="app_string">Test String</string>
</resources>我试图在“子”功能的活动中引用此字符串资源,如下所示:
int resId = R.string.app_string;Android似乎尊重这个引用,甚至在我单击它时会将我引导到app_string资源。但是,在编译期间,我遇到以下错误消息:
Error:(13, 25) error: cannot find symbol variable app_string用于我的“子”特性的build文件也具有依赖性:
dependencies {
...
implementation project(':base')
}我也尝试过compile project(':base'),但没有成功。
有什么东西是我错过的吗?
发布于 2017-06-22 02:54:40
您的基本模块和子模块有不同的包名--假设它们是com.example.base和com.example.child。每个资源都包含自己的一组资源,它们的标识符将在单独的R包中收集:
com.example.base.Rcom.example.child.R因为您试图访问基模块中定义的资源,所以需要使用变量的完全限定名(即com.example.base.R.string.app_string )引用它。
https://stackoverflow.com/questions/44688018
复制相似问题