This project demonstrates sharing runtime independent code between different Kotlin's runtimes (Java/Android/JavaScript). It uses Gradle build engine.
Mostly it's inspired by Jetbrains' code - here
otlin is a programming language developed by Jetbrains. It's fully compatibile with Java runtimes and also there is (currently experimental) support for JavaScript transpilation.
- writes Hello World!
- calculates first 1000 prime numbers (this part is shared between runtimes) and prints them
hello_android
- version for Android runtimehello_java
- version for Java runtimehello_ikvm
- version for IKVM - .NET runtimehello_js
- version for JavaScript (web browser) runtimehello_shared
- shared Kotlin code (calculating prime numbers)web
- demo web page for JavaScript version
Currently it's done by using sourcefiles from hello_shared
module. In older versions, it was done by terrible hack and this approach is much simpler.
Unfortunately hello_js
module has still some issues with dependency recognition in IntelliJ, also it requires compile dependency, so the hello_shared
module gets compiled twice. I hope that there would be some change in kotlin2js
plugin to allow properly include other source files.
It was checked only under Linux Mint, probably there won't be any problems with most Unix-like environments.
You can use Android Studio to run the application. To build from command line, you can use
# ./gradlew hello_android:build
and APK file is located in your build
directory.
![Hello Android] (.images/hello_android.png)
# ./gradlew hello_java:build
You can than run the JAR file using java -jar
command.
![Hello Java] (.images/hello_java.png)
# ./gradlew hello_ikvm:ikvm
IKVM is experimental compiler of Java bytecode to .NET bytecode. So this makes hello_ikvm.exe
file in hello_ikvm/build/libs
directory. It can be executed on Windows or using Mono/Wine on Linux.
# ./gradlew hello_js:build
Web files are stored in hello_js/web
.
You can use some web server or Open in Browser option in context menu on file in IntelliJ.
![Hello JavaScript] (.images/hello_js.png)
# ./gradlew tasks --all
Do whathever you want with this.