Kotlin is leading the pack of new JVM languages in the mobile space these days. Combining Kotlin with RoboVM allows you to not only target Android, but also use Kotlin on iOS, and share code between your frontends and backend.

To help spread the word, we started a Kotlin contest a few weeks ago. Read about the details on our contest site and submit until the 14th of December!

Getting Started with Kotlin on mobile

If you are using IntelliJ Community or Ultimate editions, you can install RoboVM from the JetBrains Plugin Repository.

You can also just download and install our custom build of IntelliJ, RoboVM Studio, which bundles up everything you need to get started.

No matter how you installed RoboVM, once your IDE launches, you can click on “Create New Project”. Under the RoboVM section, select the new cross platform template for Kotlin. Then fill in the details about your app.

Your new project consists of three modules: ios, android, and core.

In the Android project you will create your UI using the Android Designer tool and Kotlin extensions for android.

For iOS, you will use Interface Builder and the Robovm APIs.

And finally, The core module is where the bulk of your code will go, like database access and business logic. This module is shared between the your Android and iOS apps.

RoboVM Studio has already created run configurations for all the simulators and devices available, so to try out your first Kotlin cross-platform application, choose one from the drop down and press Run or Debug.

From here you should check out the docs at the Kotlin and RoboVM websites, which provide more in depth references and tutorials.

A brief tour of Kotlin features

Not only is Kotlin 100% compatible with Java, Kotlin also provides sophisticated features that allow you reduce boilerplate and maximize safety.

Automatic getters, setters, …

You can create plain old Java objects with getters, setters, equals(), hashCode(), toString() and copy() in a single line.

Don’t fear the NullPointerException

The type system protects you from mistakenly operating on nullable types, including those from Java.

Lambdas

Lambdas are ready to be used in your projects today, even on Android.

Properties

You finally have access to properties. These can be declared read-only or mutable, and have custom accessors.

Extensions

Kotlin also provides the ability to extend a class with new functionality without having to inherit from the class. This is done using extension declarations.

One step at a time

You don’t even need to convert your entire project right away, because you can mix Kotlin into your existing Java projects. IntelliJ IDEA even let’s you convert Java code to Kotlin code, one class at a time. Open the Java class you want to convert, then hit the Code menu and select Convert Java file to Kotlin:

convert-java-to-kotlin

This is just a birds eye view on what Kotlin has to offer. To learn more about Kotlin, check out the official Kotlin site. To get up to speed quickly, have a look at the Kotlin Koans!

Let us know what you come up with, and Happy Coding!