Mik*_*rov 6 android android-resources android-module
我有一个带有几个 gradle 模块的 android 项目。模块之间的依赖关系如下所示:
app <-- coremodule <-- featuremodule
coremodule中有资源(字符串和颜色)。
当我在功能模块的布局中使用它们时,一切正常,它们可用并且按预期工作。但是当我尝试从功能模块的 Activity 中以编程方式获取它们时,我得到一个异常:未解析的引用:R
所以android:text="@string/res_from_core_module" 有效和myTextView.setText(R.string.res_from_core_module) 无效。
有谁知道为什么会发生以及如何解决这个问题?
出现这种行为的原因是使用compileOnly添加了“coremodule”依赖项。
应用程序模块的 build.gradle 如下所示:
dependencies {
...
compileOnly project(path: ':coremodule')
...
}
Run Code Online (Sandbox Code Playgroud)
如果使用实现(或api)更改compileOnly,则一切正常
dependencies {
...
implementation project(path: ':coremodule')
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7088 次 |
| 最近记录: |