https://kotlinlang.org logo
#kapt
Title
# kapt
o

okaymak

07/04/2018, 2:14 PM
Getting this error when creating a custom
DataBindingComponent
inside a library module which is being used from an app module (in an android project):
Copy code
e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
    class <redacted>.CustomComponent, unresolved supertypes: android.databinding.DataBindingComponent
Is this a bug in kapt?
Tested with Kotlin 1.2.50 and 1.2.51
g

gildor

07/04/2018, 4:27 PM
I don't think that this is a bug of kapt, more likely some problem with your dependencies or build config. Are you sure that your module has runtime dependency of databindings?
o

okaymak

07/04/2018, 9:22 PM
Databinding has been setup correctly in both modules using:
build.gradle:
Copy code
apply plugin: 'kotlin-kapt'

...

dataBinding {
   enabled = true
}
This is created inside the library module:
Copy code
class LifeCycleBindings(private val lifecycle: LifeCycle): LifecycleObserver {
    val disposables = CompositeDisposable()

    init {
        lifecycle.addObserver(this)
    }

    @BindingAdapter("test")
    fun TextView.test(test: String) {
	// just for demoing
        disposables.add(....)
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    fun dispose() {
        disposables.dispose()
    }
}
Building the project generates the following in both modules (by kapt?):
Copy code
package android.databinding;

public interface DataBindingComponent {
    LifeCycleBindings getLifeCycleBindings();
}
Creating the following inside the library module (and using it in the app module), gives the aforementioned error:
Copy code
class LifecycleBindingComponent(private val lifecycle: Lifecycle) : DataBindingComponent {
    override fun getLifeCycleBindings(): LifeCycleBindings {
        return LifeCycleBindings(lifecycle)
    }
}
But creating this file inside the app module (and using it in the app module) works without any problems. I want to provide a ready made
LifecycleBindingComponent
for the consumers of this library, without having to force the consumer to create a class.
@yan ^^ I can create a sample project if it helps.
y

yan

07/14/2018, 12:30 AM
@okaymak It would be very appreciated.
10 Views