Setup Environment with Command Line Compiler
1) Compiler setup
The kotlin/Native compiler is available for macOS, Linux, and Windows. It is available as a command line tool and Jetbrain and Kotlin team ships as part of Standard Kotlin distribution. Kotlin every release with a stand-alone compiler, Download the latest version from GitHub Releases
Target Platforms
Kotlin/Native Supports following Platforms:
- iOS (arm32, arm64, simulator x86_64)
- macOS (x86_64)
- tvOS (arm64, x86_64)
- watchOS (arm32, arm64, x86)
- Android (arm32, arm64, x86, x86_64)
- Windows (mingw x86_64, x86)
- Linux (x86_64, arm32, arm64, MIPS, MIPS little endian)
- WebAssembly (wasm32)
While cross-platform compilation is possible, which means using one platform to compile for a different one, in this case we'll be targeting the same platform we're compiling on.
Manual Install
Unzip the stand-alone compile into a directory and optionally add the bin directory to the your system path. '
SDKMAN!
Another easier way to install kotlin on UNIX based operating systems such as Linux, OS X, Cygwin, FreeBSD and solaris by using SDKMAN!
$ curl -s https://get.sdkman.io | bash
now open a new terminal and install kotlin with:
$ sdk install kotlin
Homebrew
Another way on OS X you can install the compiler via Homebrew.
$ brew update
$ brew install kotlin
Chocolatey package
For users of Chocolatey on Windows, there is a community-maintained kotlinc package. You can install it from the command line using the choco install
command.
2) First application
A simple application in Kotlin that display Hello World!
fun main(args: Array<String>){
println("Hello, World!")
}
fun means define a function
main is by convention the entry point for an application — the main function
(…) is a list of the function’s arguments
args in this case, is the name of the single argument to the function
: Array<String> is the type of the argument, in this case, an array of Strings
So, it passes the command line arguments into the the starting function of an application.
Compile the application using the Kotlin compiler
$ kotlinc hello.kt -include-runtime -d hello.jar
$ kotlinc -help
$ java -jar hello.jar