I have a simple LayoutSpec that returns a single Text item. Defining it in Kotlin:
@LayoutSpec
class CurrentWeatherTopSpec {
companion object {
@JvmStatic
@OnCreateLayout
fun onCreateLayout(c: ComponentContext): ComponentLayout {
return Column.create(c)
.child(Row.create(c)
.child(
Text.create(c)
.text("Current Weather")
.build()
).build())
.build()
}
}
}
Nothing gets generated. No CurrentWeatherTopLayout file created. If I create the same code in Java, it gets generated:
@LayoutSpec
class CurrentWeatherTopSpec {
@OnCreateLayout
static ComponentLayout onCreateLayout(ComponentContext context) {
return Column.create(c)
.child(Row.create(c)
.child(
Text.create(c)
.text("Current Weather")
.build()
).build())
.build();
}
}
I'd expect the corresponding generated component class.
Is this a bug or something I am doing wrong here?
I guess my real question here is what does Litho use to determine if the class is a proper @LayoutSpec. Also FYI im using kapt and using it for java files works fine, but when in Kotlin the processor does not work.
Are you using kapt3 or legacy kapt? I'm not certain, but I don't think legacy kapt will work with litho.
looks like legacy KAPT. Is there a reason why legacy won't work? Its strange that java files work in kapt but not Kotlin files.
Legacy kapt used to convert kotlin code into stub class files, which in turn were run through the javac annotation processing tool. One of the (many) limitations of this idea is that class files don't have any information about method parameter names, which this library depends on. Lots of information in this article: https://medium.com/@workingkills/pushing-the-limits-of-kotlin-annotation-processing-8611027b6711
ok. now that would make a lot more sense. would it be possible to add this in the getting started docs or somewhere else so it's clear? Thank you!
I have yet to try using Litho with Kotlin. If you want to start some docs on how to do it, we'd certainly love to include it.
@grandstaish According to #119 it seems you got Litho to work with Kotlin. For some reason I'm running into the same problem like @agrosner meaning nothing gets generated. Would you mind setting up an example project so that we can compare our configurations?
Okay, got it working as well. I created a minimalistic project on Github pointing out Kotlin specific adaptions: https://github.com/ubuntudroid/litho-kotlin.
Irrelevant! Project already contains a Kotlin sample now :)! Can be closed!
Most helpful comment
Okay, got it working as well. I created a minimalistic project on Github pointing out Kotlin specific adaptions: https://github.com/ubuntudroid/litho-kotlin.