Kotlin for Pebble
Andrei
Posted on March 3, 2018
The best Smartwatchs are Pebble. Even taking into account that the company producing them was sold, and there will be no more new devices it is still best smartwatchs you can buy.
It is specially true if you are a software developer or just love to play with code. Pebbles provides you with powerful but simple SDK for C and Javascript. And cool web IDE — CloudPebble. As a result, it is super easy to develop apps and watchfaces.
But you probably know I am a big fan of Kotlin, so C and Javascript were not definitely enough for me! Since Kotlin-native at this moment doesn’t support the platforms are used in Pebble I’ve decided to go with KotlinJS.
KotlinJS is a way to transpile Kotlin code to Javascript. As a starting point, I took this repo — https://github.com/pebble/pebblejs. This repo provides you the way to develop apps for Pebble in Javascript locally.
First, you need to follow this https://developer.pebble.com/sdk/install/ instructions to setup PebbleSDK. Also, you need to setup Kotlin command line tools. I am using SDKMan for that. As soon as you have all that you are good to go.
So, I’ve made a fork of pebblejs repo — https://github.com/gimlet2/pebblekt. The first thing to check here is build.sh script. It has three steps:
- Build Kotlin code to Javascript with kotlinc-js
- Remove unused code with help of kotlin-dce-js
- And pebble build to actually produce artifact for Pebble
- The last step which is not the part of the script — installation — you can use different options of pebble install command.
The last thing to focus on — src folder:
- in js folder you will find original PebbleJS SDK. Also a result of Kotlin transpiling is also could be found here in app.js file.
- KotlinJs standard library could be found in kotlinjs folder. It is huge but kotlin-dce-js is there to fix this.
- And finally, kotlin folder contains bindings to js code(for example ui.kt ), some helper functions in pebble.kt and app.kt — the application code.
If you build and run this code you’ll get typical Hello world app.
With this project I want to try to expand Kotlin to a new platform. Worth to mention the latest release of Kotlin-native (0.6.0) with a support of STM32 chips. But that is a story for another post.
Posted on March 3, 2018
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.