Kotlin for Pebble

Andrei Chernyshev
Feb 16, 2018 · 2 min read

The best Smartwatches 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 smartwatches you can buy.

Image for post
Image for post

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:

  1. Build Kotlin code to Javascript with kotlinc-js
  2. Remove unused code with help of kotlin-dce-js
  3. And pebble build to actually produce artifact for Pebble
  4. 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:

  1. 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.
  2. KotlinJs standard library could be found in kotlinjs folder. It is huge but kotlin-dce-js is there to fix this.
  3. 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 like this:

Image for post
Image for post

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.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store