question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Kotlin LayoutSpec files not found by the Processor

See original GitHub issue

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:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ubuntudroidcommented, Apr 28, 2017

Okay, got it working as well. I created a minimalistic project on Github pointing out Kotlin specific adaptions: https://github.com/ubuntudroid/litho-kotlin.

1reaction
grandstaishcommented, Apr 21, 2017

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found