• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

wojta/hello-kotlin-multiplatform: Multiplatform Kotlin Hello World (Android/Java ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

wojta/hello-kotlin-multiplatform

开源软件地址(OpenSource Url):

https://github.com/wojta/hello-kotlin-multiplatform

开源编程语言(OpenSource Language):

Kotlin 90.4%

开源软件介绍(OpenSource Introduction):

CircleCI

Multiplatform Kotlin Hello World

This project demonstrates sharing runtime independent code between different Kotlin's runtimes (Java/Android/JavaScript). It uses Gradle build engine.

It uses new support for multiplatform modules with plugin kotlin-multiplatform.

Applications are built using features available from Kotlin 1.2 regarding multiplatform modules - see this blog posts:

Older implementation that didn't use kotlin-multiplatform plugin and various hacks was moved to old-multiplatform branch. Oldest implementation that used various hacks was moved to old-multiplatform branch.

What is Kotlin?

Kotlin otlin is a programming language developed by Jetbrains. It's fully compatibile with Java runtimes and also there is support for JavaScript transpilation. Experimental version of Kotlin/Native has goal to also build fully native apps for iOS, Linux, Windows and possibly other platforms.

What is it doing?

  • writes Hello Kotlin!
  • calculates first 1000 prime numbers (this part is shared between runtimes) and prints them

Structure

It's the Gradle multiple modules project.

  • hello_android_app - Android application module, it's compiled to DEX bytecode, it produces APK file upon build
  • hello_js_browser_app - application transpiled for frontend JavaScript, packed in WebPack, it's only statically served by Node.js
  • hello_js_node_app - console application transpiled to Node.js JavaScript
  • hello_jvm_app - console application compiled to Java bytecode for JVM, produces JAR that can be executed by eg. Oracle JVM
  • hello_lib - multiplatform library project, with shared and platform specific code
    • commonMain - shared Kotlin source code, platform independent code
    • commonTest - shared tests, platform independent tests
    • jsMain - JavaScript runtimes platform dependent code
    • jsTest - JavaScript runtimes specific tests
    • jvmMain - Java runtime platform dependent code
    • jvmTest - Java runtime specific tests
    • androidMain - Android runtime platform dependent code
    • androidTest - Android runtime specific tests

Modules dependency

Platform implementation specifics

  • prime number calculation is platform independent, single code shared for all platforms
  • text output on screen is platform dependent
    • Android - it's done by adding with TextView to layout
    • Frontend JavaScript - it adds element in DOM of HTML page
    • Node.js JavaScript - uses console.log()
    • JVM - uses System.out.println()

Note: Ordinary console output can be done by println() function from Kotlin Standard Library.

Implementation in modules

Building and running the demo

It was checked only under Linux Mint, probably there won't be any problems with most Unix-like environments.

Android application

You can use Android Studio to run the application. To build from command line, you can use

# ./gradlew hello_android_app:build

and APK file is located in your build/outputs/apk directory.

Hello Android

JVM console application

# ./gradlew hello_jvm_app:build

You can than run the JAR file using java -jar hello_jvm_app.jar command from build/libs directory.

Hello JVM

Frontend JavaScript application

# ./gradlew hello_js_browser_app:build

Webpack allows to host site directly from Gradle by

# ./gradlew hello_js_browser_app:run 

It will run locally on http://localhost:8088/.

Hello JavaScript Browser

Node.js console application

# ./gradlew hello_js_node_app:build

You can execute it in hello_js_node_app directory by:

# node ./app.js

Hello JavaScript Node.js

to see all build options

# ./gradlew tasks --all

License

Do whathever you want with this.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap