Go on Android

GothamGo

15 Nov 2014

David Crawshaw

Google

Video

This talk was presented at GothamGo in New York City, November 2014.

2

Go on Mobile

The goal is to bring Go to Android and iOS,
starting with Android.

This is new territory for Go and a well-established
ecosystem. A lot of experimentation is necessary.

3

Today

4

Go 1.4 Status

The coming 1.4 release can build binaries for Android OS.

With the mobile subrepository and the Android SDK/NDK, it can:

5

What's there

Packages for cross-device apps:

6

What's missing — a good build system

There's more than one way to build an Android App.

None of them

We are working on this for Go 1.5.

Until it is done, using Go on Android requires some bravery.

7

What it's for — the two kinds of apps

SDK Apps

Write your Android UI in Java.
Write your iOS UI in Objective-C/Swift.
Write your logic in Go.

Share the Go using interfaces generated by gobind.

NDK Apps

Games.

Use OpenGL or the coming 2D sprite package to write to the screen.
Everything is written in Go.

8

Hello, World!

Portable APIs, just Go. This is a complete app:

package main

import (
    "golang.org/x/mobile/app"
    "golang.org/x/mobile/app/debug"
    "golang.org/x/mobile/gl"
)

func main() {
    app.Run(app.Callbacks{
        Draw: draw,
    })
}

func draw() {
    gl.ClearColor(1, 0, 0, 1) // RGBA value used to clear buffer: red
    gl.Clear(gl.COLOR_BUFFER_BIT)
    debug.DrawFPS()
}
9

Write anywhere

Developing with portable APIs means starting from very little.
It is a lot of work to get going and limits access to device features.

But it also frees us from device-specific build systems.

The app package includes Mac/X11 shims for starting as normal programs.
We can write Apps anywhere we can write Go.

(Windows coming soon.)

10

Touch events

package main

import (
    "fmt"

    "golang.org/x/mobile/app"
    "golang.org/x/mobile/event"
    "golang.org/x/mobile/gl"
)

func main() {
    app.Run(app.Callbacks{
        Draw: func() {
            gl.ClearColor(0, 0, 1, 1) // blue
            gl.Clear(gl.COLOR_BUFFER_BIT)
        },
        Touch: func(e event.Touch) { fmt.Println(e) },
    })
}
11

Package sprite

We are building a 2D rendering and compositing package.

It renders a scene graph. A scene starts with a root
*sprite.Node, which can have child nodes.

Each node may have an affine transform and texture.

Rendering is done in a depth-first traversal of the scene,
with transforms applied relative to the parent.

Composition is done in OpenGL.

12

Sprite — affine transform

13

Sprite — depth first traversal, applying parent's transforms

14

Sprite Demo

15

Sprite — what's next

16

Go 1.5 Plans (July 2015)

17

Thank you

GothamGo

15 Nov 2014

David Crawshaw

Google

Use the left and right arrow keys or click the left and right edges of the page to navigate between slides.
(Press 'H' or navigate to hide this message.)