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?
-
Yes, you can, why not?– Dmytro RostopiraCommented Feb 19, 2017 at 18:40
-
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?– GrahamCommented Feb 19, 2017 at 20:17
-
If they use Gradle - you can use Kotlin. It's just a gradle plugin + standard library, not separate compilator– Dmytro RostopiraCommented Feb 19, 2017 at 20:31
-
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.– GrahamCommented Feb 19, 2017 at 20:40
-
1Just edited my answer based on a new announcement we made. We will introduce Kotlin support later this year: codenameone.com/blog/…– Shai AlmogCommented Jun 13, 2017 at 13:27
1 Answer
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
-
2In 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. Commented Feb 20, 2017 at 17:09