库模块中的Kotlin Android扩展布局无法解析 [英] Kotlin Android Extension layouts from library module cannot be resolved
问题描述
我有我的buyer
,seller
模块和一个common
模块.在common
模块中放置的buyer
和seller
模块中很少使用的布局.
I have my buyer
, seller
module and a common
module. Few layouts which are used in both buyer
and seller
module are placed in common
module.
common -> layout_toolbar.xml
buyer -> activity_sell.xml ->
<LinearLayout>
<include layout="@layout/layout_toolbar" /> <!-- layout_toolbar.xml is from common module -->
</LinearLayout>
seller -> activity_buy.xml ->
<RelativeLayout>
<include layout="@layout/layout_toolbar" /> <!-- layout_toolbar.xml is from common module -->
</RelativeLayout>
buyer -> BuyActivity.kt
toolbar.title = "Buy"
seller -> SellActivity.kt
toolbar.title = "Sell"
在IDE中一切正常,
- 通过解析include标记并在IDE的布局预览中进行放大,可以正确显示我的布局预览.
- 我的kotlin文件还可以正确解决工具栏引用,并且没有任何问题.
但是每当我尝试构建应用程序时,它都会给我带来编译器错误:
But whenever I try to build the app, it gives me the compiler error:
Unresolved reference: toolbar <-- Id of the toolbar inside layout_toolbar.xml
如果IDE可以正确解决依赖关系,为什么不能构建gradle?我在做错什么吗?
If IDE can resolve the dependencies properly, why can't the gradle build? Is there anything I am doing wrong?
请注意,在其他两个模块中,将common
模块作为implementation
添加.但是我尝试使用api
也不起作用.
Please note that common
module is added as implementation
in other two modules. But I have tried with api
which doesn't work too.
推荐答案
开始时这似乎是个好问题.我在当前项目中重现了同样的问题.
This seems to a good question at first. I reproduce the same problem in my current project.
-
我通过添加了库模块
I have added the library module via
实施项目(':mylibrary')
implementation project(':mylibrary')
在项目中添加了库模块.
Added the library module in the project.
- 在库模块(也称为通用模块)中创建布局/视图.
- 包含在主布局中
-
最后,我可以通过编程方式对其进行更改.
And finally, I am able to change it programmatically.
导入kotlinx.android.synthetic.main.activity_home.* 导入kotlinx.android.synthetic.main.item_library.*
import kotlinx.android.synthetic.main.activity_home.* import kotlinx.android.synthetic.main.item_library.*
构建环境可能存在一些问题.注意:我使用的是最新的构建版本以及android和kotlin插件.
There might be some problem with the built environment. Note: I am using latest build version and android and kotlin plugins.
请更新您的日志,以进一步澄清问题.
Do update your logs for further clarification about your problem.
这篇关于库模块中的Kotlin Android扩展布局无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!