Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use Kotlin with Codename One?

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?

like image 322
Graham Avatar asked Feb 19 '17 16:02

Graham


People also ask

Is Codename One free?

The core of Codename One is free and open source.

What is kotlin multiplatform?

Kotlin Multiplatform use casesSharing code between mobile platforms is one of the major Kotlin Multiplatform use cases. With Kotlin Multiplatform Mobile, you can build cross-platform mobile applications and share common code between Android and iOS, such as business logic, connectivity, and more.

Can you build mobile apps with Java?

Use Android Studio and Java to write Android apps You write Android apps in the Java programming language using an IDE called Android Studio. Based on JetBrains' IntelliJ IDEA software, Android Studio is an IDE designed specifically for Android development.

What is kotlin vs Java?

Key Difference Between Java and Kotlin Programming LanguagesKotlin offers object-oriented and functional features to developers. In contrast, Java only offers object-oriented programming. Kotlin offers extension creation capabilities, whereas Java doesn't offer any extension function.


1 Answers

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

like image 141
Shai Almog Avatar answered Sep 22 '22 18:09

Shai Almog