litho icon indicating copy to clipboard operation
litho copied to clipboard

[meta-task] Kotlin outstanding issues

Open passy opened this issue 8 years ago • 20 comments

This issue is to keep track of remaining issues and where applicable work-arounds when using Litho with Kotlin.

Issues

  • [X] Cannot use Kotlin objects for specs.
  • [X] Annotated methods inside specs require @JvmStatic.
  • [X] @PropDefault doesn't work.
  • [x] @PropDefault requires @JvmField annotation.

Other Gotchas

  • kapt is a pig. There seem to be a bunch of invalidation bugs that force you to clean your cache and rebuild.
  • NonExistentClass shows up in random places. Again, this appears to be a kapt bug and the best workaround for now appears to be ./gradlew clean.

Future work

We should consider generating Kotlin code to fully leverage the new language features like data classes, allow for Anko-like DSLs and get rid of builders.

passy avatar Oct 30 '17 13:10 passy

@passy @PropDefault does not work for which cases? Is there a branch with Kotlin sample available?

pavlospt avatar Oct 30 '17 13:10 pavlospt

@pavlospt I'm working on fixing that today. I think Pasquale's Kotlin sample could use this in a spot.

passy avatar Oct 30 '17 13:10 passy

@passy Have you tried @get:PropDefault val something = 1f for example ?

pavlospt avatar Oct 30 '17 13:10 pavlospt

@pavlospt Sadly, that generates even worse code for us at the moment. I've got a work-around ready with a long-ish explanation on the commit which should land probably tomorrow.

passy avatar Oct 30 '17 17:10 passy

Ok, great! Will wait to check that commit tomorrow :) Please ping it here as well in case I miss it :P

pavlospt avatar Oct 30 '17 19:10 pavlospt

@pavlospt As if you'd ever miss a commit! 😜

passy avatar Oct 31 '17 11:10 passy

@passy My colleagues usually say the same thing, no wonder why 😂

pavlospt avatar Oct 31 '17 11:10 pavlospt

@passy What kind of bugs do you experience with kapt? If you can reproduce something going bad, please submit the issue to kotl.in/issue, and we will fix it shortly.

yanex avatar Nov 08 '17 02:11 yanex

@yanex Hey! Thanks for commenting here. :)

Sadly, the main problem for us has exactly been reproducible. Everyone on our team who's worked with this has found themselves in a situation where compilation would fail for seemingly random reasons and only clearing the caches would help.

In particular, we've seen NonExistentClass in stubs appear at times. Again, one ./gradlew clean and it would be gone, but it can lead to some quite frustrating development cycles where you think you made a mistake in the codegen, but it turns out to be non-determinism in kapt.

If I see a reproducible case, I will definitely send it your way. :)

passy avatar Nov 08 '17 10:11 passy

I would add that the main issue there is that gradle clean and rebuild makes the development cycle really too slow 😢

pasqualeanatriello avatar Nov 08 '17 11:11 pasqualeanatriello

@passy Please check if you use the new version of kapt (aka kapt3, you can find the setup instructions here https://kotlinlang.org/docs/reference/kapt.html).

The original kapt definitely had architectural problems that led to random NonExistentClass errors, that is why it is deprecated now (and will be removed in Kotlin 1.2.20). If you experience NonExistingClass errors with apply plugin: 'kotlin-kapt', then it is something new.

yanex avatar Nov 08 '17 14:11 yanex

@pasqualeanatriello Kotlin incremental compilation does not support changes in Java files yet. So whenever the annotation processor generates the different .java source, Kotlin recompiles much more files that it is needed. Hopefully, we are already working on this, and we hope things will become much better very soon.

yanex avatar Nov 08 '17 14:11 yanex

If you experience NonExistingClass errors with apply plugin: 'kotlin-kapt', then it is something new.

Yes, it was with kotlin-kapt. The old one didn't seem to work for us at all. We rely on annotated source files being able to reference the generated files based on them. It seemed like this wasn't support with the old kapt, but works with the new.

I didn't know about the correctErrorTypes = true option, though. Perhaps that could help us track this down if it should come up again.

passy avatar Nov 08 '17 14:11 passy

What's the status on this? Is it feasible to use litho with Kotlin in a real life project currently?

kar avatar May 06 '18 19:05 kar

Hey @kar , you can find Kotlin-powered samples inside the repository! Check sample-barebones-kotlin and sample-kotlin for more details :)

pavlospt avatar May 19 '18 11:05 pavlospt

@passy I think it can be closed and also remove the IMPORTANT notice from this doc: https://github.com/facebook/litho/blob/master/docs/_docs/getting-started/gradle-kt.md

pavlospt avatar May 23 '18 12:05 pavlospt

I'll update the comment. As long as we don't use it in production internally, I think it's best to keep the note there to set the right expectations.

passy avatar May 24 '18 16:05 passy

@passy sure sounds reasonable!

pavlospt avatar May 24 '18 17:05 pavlospt

I made a bad judgement call of adopting https://github.com/vinc3m1/litho-kotlin, but it had really nice results. I hope you guys bring it back as an official DSL sooner rather than later.

yschimke avatar Jun 04 '18 12:06 yschimke

Will not close this one for now, but wanted to bring this to your attention: https://github.com/facebook/litho/blob/master/sample-kotlin/src/main/kotlin/com/facebook/samples/litho/kotlin/lithography/components/FavouriteButton.kt To use that you need to add litho-core-kotlin and maybe litho-widget-kotlin to your build.gradle file.

cc @yschimke

colriot avatar Jan 20 '20 18:01 colriot