Kotlin Android Extension layouts from library module cannot be resolved
Asked Answered
R

1

18

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"

Everything works fine in IDE,

  1. My layout preview shows properly by resolving the include tag and inflating in the IDE's layout preview.
  2. My kotlin files also properly resolves the toolbar reference and doesn't show any problem.

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

If IDE can resolve the dependencies properly, why can't the gradle build? Is there anything I am doing wrong?

Please note that common module is added as implementation in other two modules. But I have tried with api which doesn't work too.

Redstart answered 4/5, 2018 at 16:12 Comment(1)
Have you managed to resolve the issue?Worldling
L
2

This seems to a good question at first. I reproduce the same problem in my current project.

  1. I have added the library module via

    implementation project(':mylibrary')

  2. Added the library module in the project.

enter image description here

  1. Created a layout/view in the library module aka common module.

enter image description here

  1. Included in the main layout

enter image description here

  1. And finally, I am able to change it programmatically.

    import kotlinx.android.synthetic.main.activity_home.* import kotlinx.android.synthetic.main.item_library.*

enter image description here

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.

Love answered 4/5, 2018 at 17:34 Comment(1)
Have you built using command line or AS? If AS, can you please try from command prompt.Redstart

© 2022 - 2024 — McMap. All rights reserved.