Kotlin LayoutSpec files not found by the Processor
See original GitHub issue- I have searched existing issues and this is not a duplicate
Issues and Steps to Reproduce
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();
}
}
Expected Behavior
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.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Kotlin Annotation processor doesn't add import for generated ...
seems like the first argument in your code, which is a empty string is the package name you are missing in the generated...
Read more >Layout Specs | Litho
A layout spec is the logical equivalent of a composite view on Android; it simply groups existing components together in an immutable layout...
Read more >Litho: Creating a custom Button component - Medium
Classes annotated with @LayoutSpec will be processed by Litho's AnnotationProcessor, which will built a corresponding Component. Button ...
Read more >Kotlin Symbol Processing API
This view lists common things that are declared in the file: classes, functions, properties, and so on. SymbolProcessorProvider: the entry point.
Read more >The Guide To Your First Annotation Processor with KSP (And ...
Many libraries (including Room) are currently using KSP, instead of KAPT. You can find a list of few of them here. How Does...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, got it working as well. I created a minimalistic project on Github pointing out Kotlin specific adaptions: https://github.com/ubuntudroid/litho-kotlin.
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