Android即时应用程序 - 无法从基本要素资产中查找符号

Tyl*_*hie 3 android android-instant-apps

我有一个基本功能模块和一个功能模块(你可以称之为"孩子").所述基部特征模块具有包含strings.xml档案资产:

<resources>
   <string name="app_string">Test String</string>
</resources>
Run Code Online (Sandbox Code Playgroud)

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

int resId = R.string.app_string;
Run Code Online (Sandbox Code Playgroud)

Android Studio似乎尊重此引用,甚至app_string在我点击它时会将我引导到该资源.但是,在编译期间,我遇到以下错误消息:

Error:(13, 25) error: cannot find symbol variable app_string
Run Code Online (Sandbox Code Playgroud)

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

dependencies {
   ...
   implementation project(':base')
}
Run Code Online (Sandbox Code Playgroud)

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

有什么明显的东西让我失踪吗?

ibr*_*han 7

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

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

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