3

我有一个基本功能模块和一个功能模块(您可以称其为“子”)。基本功能模块有一个strings.xml文件资产,其中包含:

<resources>
   <string name="app_string">Test String</string>
</resources>

我尝试在“子”功能的活动中引用此字符串资源,如下所示:

int resId = R.string.app_string;

Android Studio 似乎尊重此引用,甚至会app_string在我单击它时将我定向到该资源。但是,在编译过程中,我遇到了以下错误消息:

Error:(13, 25) error: cannot find symbol variable app_string

我的“子”功能的构建 Gradle 文件也具有依赖性:

dependencies {
   ...
   implementation project(':base')
}

我也试过compile project(':base'),但没有成功。

我有什么明显的遗漏吗?

4

1 回答 1

7

您的基本模块和子模块具有不同的包名称 - 假设它们是com.example.baseand com.example.child。每个都包含自己的一组资源,它们的标识符将收集在单独的 R 包中:

  • com.example.base.R
  • com.example.child.R

因为您正在尝试访问在基本模块中定义的资源,所以您需要使用变量的完全限定名称来引用它,即com.example.base.R.string.app_string.

于 2017-06-22T02:54:40.153 回答