The State of Go Language for Android Native Development
A couple of different proposals from Google engineers and independent developers are aiming at making it possible to write native Android apps in Go. This will not go so far as allowing Go apps to access the full Android NDK, but it could allow access to a subset of it.
According to David Crawshaw, engineer at Google and author of a proposal to add partial Go support for Android apps, "providing a Go equivalent to the Android platform is intractable. The platform is written in Java and has a huge API surface."
There is however, says Crawshaw, a subset of Android apps written against a much smaller C-based API surface provided in the Android NDK: Games. Thus it becomes feasible to build Go support for Android providing the equivalent features found in the NDK.
Crawshaw proposes that during the Go 1.4 cycle, support for a
GOOS=android option will be introduced to the Go repository that will include:
- Bindings for OpenGL, OpenSL, and OpenMAX as exported through the Android NDK.
- A Java -> Go language binding generator. Given a Go package, this will let Java code call it, so game menu UIs can be built in the standard SDK.
- Android Studio build system integration.
Crawshaw's proposal to bring Go to Android is not the only one. Elias Naur suggests to extend Go toolchain so that it supports the creation of shared libraries. This would allow to create an Android app which uses a Go library loaded and run in Android apps as distributed in .apk files. An important requirement for this to happen has been already satisfied in Go 1.3 by adding support for cross-compilation. Cross-compilation is required because the NDK does not run on Android itself and only executables and shared libraries compiled and/or linked with the Android NDK are guaranteed to run on Android devices.
The latter proposal is based on an existing open-source project by Elias Naur, goandroid. Goandroid patches Go tools and runtime to allow the creation of shared libraries that can be run within native Android apps and is not officially supported by Google.
Finally, a more comprehensive framework that aims at allowing to write Android native applications in Go is Mandala. Mandala uses the Goandroid toolchain and according to its creator, Andrea Fazzi, thanks to Mandala "you can develop, test and run your application on your desktop and then deploy it to an Android device. It encourages the use of idiomatic Go for writing Android applications: communication happens through channels and not callbacks."
Mandala comes close to Crawshaw's proposal, feature-wise, and also aims at providing a solution mostly for games: "The framework should not be considered a high-level game engine but as a basic layer onto which game engines can be built or existing ones can be used." Fazzi warns that Google does not support native Android development in Go, but expresses his hope that "the present work could act as a sort of incentive in the direction of an official Android support by the Go Team."
Mike Amundsen May 29, 2015
Ben Linders May 28, 2015