Can I use Kotlin with Codename One?
Asked Answered
O

1

7

I am a big fan of Kotlin and would like to use it with Codename One instead of Java. Since Kotlin interops seamlessly with Java am I able to use it to build an app with Codename One?

Olden answered 19/2, 2017 at 16:40 Comment(7)
Yes, you can, why not?Rincon
I'm not so sure about that. Codename One does not alow local builds unless you have enterprise support. Kotlin has to be tied in with the build process in order to work. Is there a way to customize the build process on their servers they require you to use?Olden
If they use Gradle - you can use Kotlin. It's just a gradle plugin + standard library, not separate compilatorRincon
I don't think we're on the same page. Kotlin does have a compiler that compiles to Java class files. That's what Grade calls in its build process. Even if they were using Maven I could get it to work. But whether or not they allow you to customize that on their server is what I'm wondering.Olden
Kotlin plugin is added in project level build.gradle, same as Google Play Services plugin. I'm highly doubt, that they prohibited GMSRincon
javac happens on the client which is what matters here... Our server translators for iOS, Windows, JavaScript etc. are all open source so if you need something there you can use pull requests to get things donePasqualepasqueflower
Just edited my answer based on a new announcement we made. We will introduce Kotlin support later this year: codenameone.com/blog/…Pasqualepasqueflower
P
4

Updated July 2017: Public beta of Kotlin support is now available: https://www.codenameone.com/blog/kotlin-support-public-beta.html

Updated Jun 2017: We've just announced we'll do it by the end of the year: https://www.codenameone.com/blog/kotlin-wora-ios-iphone-windows-android.html

Original answer below for reference:

There is no official support for that. We contacted the Kotlin team a while back after RoboVM was discontinued and offered to help with integration but this didn't lead anywhere. If there is interest in working together from their team we'll help.

This might be something you can do yourself e.g. Steve Hannah wrote support for Mirah (a subset of Ruby) before we brought him into our team: https://www.codenameone.com/search?q=mirah

You can edit our Ant script to call a gradle script that will instrument the code before sending it onward to the compiler. I'm not sure how hard that will be and might "just work" with no further effort.

However, there could be two potential problems:

  • Creative usage of bytecode that might fail in some cases (e.g. on iOS, Windows UWP translation). This is unlikely but possible as we test only with javac

  • Usage of API's we don't have - this is possible. E.g. the Kotlin compiler might implicitly rely on parts of the Java SE API we don't support in which case the fix might be harder but doable either in Kotlin or in Codename One or somewhere in between with a pre-post processor of the bytecode

Pasqualepasqueflower answered 20/2, 2017 at 5:8 Comment(1)
In addition, Kotlin has a runtime library that needs to be included. Including this would require explicit support. And the library itself may depend on parts of the JRE that aren't yet supported by Codename One. When I added Mirah support, I chose Mirah because it was the only JVM language (other than Java) that didn't require its own runtime library.Linlithgow

© 2022 - 2024 — McMap. All rights reserved.