blob: ec9fd1c5d351956fc6911206f1157c7a1638f501 [file] [log] [blame]
Go on Android
GothamGo
15 Nov 2014
David Crawshaw
Google
@davidcrawshaw
* Video
This talk was presented at GothamGo in New York City, November 2014.
.link http://vimeo.com/115307069 Watch the talk on Vimeo
* 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.
* Today
* 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:
- Build `.so` files for linking into Android Apps
- Build apps based on NativeActivity ("All Go")
* What's there
- Go standard library tests running on Android OS
- JDK / runtime hooks
- The `gobind` tool, for calling Go from Java: [[http://golang.org/s/gobind]]
Packages for cross-device apps:
- [[https://godoc.org/golang.org/x/mobile/app][App control]]
- [[https://godoc.org/golang.org/x/mobile/gl][OpenGL ES 2]]
- [[https://godoc.org/golang.org/x/mobile/event][Touch events]]
- [[https://godoc.org/golang.org/x/mobile/geom][Screen geometry]]
* What's missing a good build system
There's more than one way to build an Android App.
None of them
- fit well with what go programmers expect (the go tool)
- work for cross-device development
We are working on this for Go 1.5.
Until it is done, using Go on Android requires some bravery.
* 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 [[http://godoc.org/golang.org/x/mobile/sprite][sprite]] package to write to the screen.
Everything is written in Go.
* Hello, World!
Portable APIs, just Go. This is a complete app:
.play gothamgo-android/red.go
* 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.)
* Touch events
.play gothamgo-android/touch.go
* 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.
* Sprite affine transform
.image gothamgo-android/sprite_affine.svg
* Sprite depth first traversal, applying parent's transforms
.image gothamgo-android/sprite_subtex.svg
* Sprite Demo
* Sprite — what's next
- Rasterizer, CPU-based for now
- Text, based on freetype-go
- Simple UI elements, focused on game menu needs
- Debugging tools
- Performance
* Go 1.5 Plans (July 2015)
- A build system
- OpenAL bindings for sound
- Very basic UI building blocks for game-like apps
- iOS experimental support