Unresolved reference for synthetic view when layout is in library module

Update:

Synthetic view references have been deprecated and will not be supported in the future.

The current recommended solution is to use ViewBinding (or wait for Jetpack Compose)

Original Answer:

One way to solve this is to create an “alias” property that can be consumed from other modules:

// SyntheticExports.kt
package com.example.synthetic.exported

import kotlinx.android.synthetic.main.layout_in_library.*

inline val Activity.exported_text_view get() = text_view

Then on the other module:

// MainActivity.kt
import com.example.synthetic.exported.exported_text_view

exported_text_view.text = "example"

That works for us. Have to create different extensions for view, fragment, etc. It’s a bit tedious to have to do them manually but this is the simplest workaround we found.

Extra: This is also a decent method to export synthetic extensions as part of a public library too, not just in an internal module.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)