【问题标题】:Kotlin Android Extension layouts from library module cannot be resolved无法解析来自库模块的 Kotlin Android 扩展布局
【发布时间】:2018-10-15 04:36:51
【问题描述】:

我有我的buyerseller 模块和一个common 模块。在buyerseller 模块中使用的很少布局被放置在common 模块中。

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 中一切正常,

  1. 通过解析包含标记并在 IDE 的布局预览中膨胀,我的布局预览正确显示。
  2. 我的 kotlin 文件也正确解析了工具栏引用,并且没有显示任何问题。

但每当我尝试构建应用程序时,都会出现编译器错误:

Unresolved reference: toolbar <-- Id of the toolbar inside layout_toolbar.xml

如果IDE可以正确解决依赖关系,为什么gradle不能构建?是不是我做错了什么?

请注意common 模块在其他两个模块中添加为implementation。但我尝试过 api 也不起作用。

【问题讨论】:

  • 您解决了这个问题吗?

标签: android gradle kotlin kotlin-android-extensions


【解决方案1】:

起初这似乎是一个好问题。我在当前项目中重现了同样的问题。

  1. 我已经通过

    添加了库模块

    实施项目(':mylibrary')

  2. 在项目中添加了库模块。

  1. 在库模块(即通用模块)中创建了布局/视图。

  1. 包含在主布局中

  1. 最后,我能够以编程方式更改它。

    导入 kotlinx.android.synthetic.main.activity_home.* 导入 kotlinx.android.synthetic.main.item_library.*

构建的环境可能存在一些问题。注意:我使用的是最新的构建版本以及 android 和 kotlin 插件。

请更新您的日志以进一步澄清您的问题。

【讨论】:

  • 你是用命令行还是 AS 构建的?如果是 AS,请您在命令提示符下尝试。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-23
  • 1970-01-01
  • 2017-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多