using Kotlin 1.20.20 (not that it matters, older versions behaves the same)
When layout is in separate library module Android Studio has no problem finding and refer
In an incremental improvement on @pablisco's solution above, in my library I have a file:
// SyntheticExports.kt
@file:Suppress("ClassName")
package com.example.library.synthetic.main
import android.view.TextView
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.common_layout.view.rootLayout as syntheticRootLayout
import kotlinx.android.synthetic.main.common_layout.view.retryButton as syntheticRetryButton
object common_layout {
object view {
inline val View.rootLayout: ViewGroup get() = syntheticRootLayout
inline val View.retryButton: TextView get() = syntheticRetryButton
}
}
Then on the other module:
// MainActivity.kt
import com.example.library.synthetic.main.common_layout.view.rootLayout
import com.example.library.synthetic.main.common_layout.view.retryButton
rootView.rootLayout.isVisible = true
rootView.retryButton.setOnClickListener { doIt() }
If this issue is ever fixed, I just need to change imports to start with "kotlinx.android" instead of "comp.example.library".