• Stars
    star
    1,046
  • Rank 42,351 (Top 0.9 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The android-go project provides a platform for writing native Android apps in Go programming language.

android-go Go Report Card Lines of Code

The android-go project aims to provide a platform (namely an SDK) for writing native Android apps in Go programming language. All things here were designed to be less coupled as possible, thus maintaining a great level of flexibility while keeping things simple and easy to use. The approach and tools are different from gomobile, please distinguish them apart.

The project was one of the best Go Newsletter items of 2016. In this final issue of the year, they look back at the most popular Go news and links of 2016. 🌟

❗️Important! Please see cmd/android-project utility that replaces the original android from SDK that has been stripped in latest SDK releases. All example Makefiles were updated, I advise you to do the same rather than stick to old SDK versions.

Project structure

android GoDoc

Package android provides Go bindings for the Android NDK API. They've been automatically generated by c-for-go using the official NDK headers from android-23 platform. Keep in mind that different NDK platforms may implement different sets of API available, thus some of features used by this binding may not be available in older versions of platform. But I tested with the android-21 toolchain and got no issues. Some files, like android/sensors.go for example, have been written by hand to expose some features that CGO does not handle well.

This package allows to write code that works directly with NDK API, bypassing all the CGO bookkeeping and boilerplate bloat in your code. But safety is strictly advised. There is also a JNI calling mechanism that allows easy interactions with Java VM and exposes the full potential of Android SDK! See android/jni_util.go for example of toggling Android keyboard and other JNI-based utils.

Example usages: app/queue.go, example, example-egl, nk-android.

cmd/android-project

Tool android-project is a simple replacement for infamous android util from Android SDK, prior to Android SDK Tools Revision 25.3.0 (March 2017) release when they dropped that util abruptly and got back a stripped version later. Needs to be installed first:

go get github.com/xlab/android-go/cmd/android-project

app GoDoc

Package app implements a NativeActivity glue layer required to properly handle the startup process and the native activity events. Import this package into your Go application to make it Android-compatible. Some pieces required for a proper main.main trampoline have been borrowed from gomobile, the absolute minimum to get this stuff invokable as a native activity. Most of the code in this package provides wrappers around NativeActivity event callbacks.

Example usages: example, example-egl, nk-android.

egl GoDoc

Package egl provides Go bindings for EGL API. They've been automatically generated by c-for-go using the official NDK headers from android-23 platform. All functions have their reference to the offical Khronos documentation. Some files, like egl/errors.go for example, have been written by hand to expose some features that would make it more idiomatic in the Go world.

Examples of usage in conjuction with the android package: example-egl, nk-android.

gles GoDoc

Package gles provides Go bindings for the OpenGL ES v1 API. They've been automatically generated by c-for-go using the official NDK headers from android-23 platform. All functions have their reference to the offical documentation.

Example of usage in conjuction with the android package: example-egl.

gles2 GoDoc

Package gles2 provides Go bindings for the OpenGL ES v2 API. They've been automatically generated by c-for-go using the official NDK headers from android-23 platform. All functions have their reference to the offical documentation.

Example of usage in conjuction with the android package: nk-android.

gles3 GoDoc

Package gles3 provides Go bindings for the OpenGL ES v3 API. They've been automatically generated by c-for-go using the official NDK headers from android-23 platform. All functions have their reference to the offical documentation.

Example of usage in conjuction with the android package: nk-android.

gles31 GoDoc

Package gles31 provides Go bindings for the OpenGL ES v3.1 API. They've been automatically generated by c-for-go using the official NDK headers from android-23 platform. All functions have their reference to the offical documentation. The OpenGL ES computing API is supported.

Examples

Refer the example links to get more info about them.

There are three examples. The first example is a template app showing how to create and build an Android application using the absolute minimum of code and boilerplate. It also shows the primitives of an activity and how to handle activity events, there is no visual part, so be ready to read the lines from the ADB logcat. If this one works correctly on your device, my congratulations. If not, please open an issue.

The example-egl leverages all three packages together: android, egl and of course gles (OpenGL ES 1.0) to create an visual app that animates its color based on the accelerometer values. It also reads input events such as key events and multitouch motion events (with pressure, if supported by the device), you can check these events in the ADB logcat. Please see the video of the expected behaviour:

Golang + EGL/GLES App on Android

And recently I took nuklear package and implemented a few backends in Go, including two for Android that initialize OpenGL ES 2 or ES 3 context using android, egl, gles2 and gles3 packages. They also responsible for handling touch and other input events. So now it is possible to create GUI apps for Android, see nk-android for an example Nuklear GUI app.

Nuklear GUI App written in Golang runs on Android

Android keyboard toggling video.

On existing tools or why not just use Gomobile

TL;DR it's a "three wheel bicycle" in terms of hacking flexibility. Conversely, this project tries to fill the niche by providing a platform that is minimal as possible and respects the bleeding-edge features such as OpenGL ES 3.1, ES 3.2 and of course Vulkan API.

GoMobile has different aims and motivation with a lot of implications. First of all, it has been grown as a bootstrap-script. That's it: a tool with a lot of hardcoded logic that helped to popularize Go on mobile platforms. Still provides a simple way to start building Android and iOS apps in no time, without diving deeply into any of the platform-specific complications. It provides a lot of wrappers and helpers that abstract all the platform-related boilerplate and logic away, making your apps look the same on any platform: Android, iOS, PC (Linux/OS X/Windows).

Also, considering that binding feature of GoMobile, it's a good option to use when you already have lots of Java/Obj-C code and want to integrate some of Go libs into the project. The tool is mostly for experienced mobile developers who just want to try Go sometimes. They provide a framework that hides platform details, but they also may be to restrictive and limited due to this and can't be used for crazy experimenting stuff.

An example: for Android developent, gomobile defaults to r10 SDK with android-15 stripped-down NDK, there is a lot of code written to automate this process and there is no way to override this environment, even by rewriting a lot of gomobile bootstrapping code. It's a great mess. I wasted too much time trying to switch to the r12-beta1 SDK and the android-23 NDK platform. Instead of providing a good document how to build the Go-based apps and incorporate them into any of the existing development process, GoMobile project introduces tons of hardcoded scripts.

Contributing

Feel free to share bugs, I expect a lot of weird cases. Please also share this project in social networks so more people would know how to write Go apps for Android that are not limited.

License

All the code except when stated otherwise is licensed under the MIT license.

More Repositories

1

c-for-go

Automatic C-Go Bindings Generator for Go Programming Language
Go
1,384
star
2

treeprint

Package treeprint provides a simple ASCII tree composing tool.
Go
387
star
3

pocketsphinx-go

CMU PocketSphinx for Golang, a lightweight speech recognition engine.
C
296
star
4

libvpx-go

Package vpx provides Go bindings for libvpx-1.6.0, the WebM Project VP8/VP9 codec implementation.
C
190
star
5

go-lambda

A multi-purpose tool for creating and managing AWS Lambda instances backed by arbitrary Go code
Go
146
star
6

closer

Package closer ensures a clean exit for your Go app.
Go
132
star
7

at

AT is a framework written in Go for communication with AT-compatible devices like Huawei modems via serial port.
Go
113
star
8

matchbox-keyboard

A mirror of matchbox-keyboard tree + my patches
C
63
star
9

netsed

Mirror of http://silicone.homelinux.org/git/netsed.git/
C
59
star
10

structwalk

Battle-tested Go struct and map traversal utilities.
Go
31
star
11

portmidi

The package provides Go bindings for PortMIDI from the PortMedia set of libraries.
Go
26
star
12

teg-workshop

Go
25
star
13

handysort

Alphanumeric string sorting algorithm implementation in Go
Go
24
star
14

tablewriter

The platform-independent fork of Go ASCII Table Generator, ported from the Ruby terminal-tables library.
Go
24
star
15

vorbis-go

Package vorbis provides Go bindings for OggVorbis implementation by the Xiph.Org Foundation.
C
23
star
16

libpd-go

Package libpd provides an idiomatic Go-lang wrapper for Pure Data embeddable audio synthesis library.
Go
19
star
17

portaudio-go

Package portaudio provides Go bindings for PortAudio.
Go
18
star
18

ios-go

The iOS-go project provides a platform for writing native iOS apps in Go programming language.
Go
17
star
19

opus-go

Package opus provides Go bindings for Opus encoder/decoder reference implementation by Xiph.org
C
16
star
20

gitio

A git.io client for Go, also a CLI utility.
Go
13
star
21

pace

Package pace provides a threadsafe counter for measuring ticks in the specified timeframe.
Go
9
star
22

pkgconfig

A lightweight pkg-config(1) clone written in Go.
Go
7
star
23

alac-go

Package alac provides Go bindings for ALAC decoder (C version by David Hammerton) with community patches.
C
5
star
24

suplog

Supercharged Go logging based on Logrus
Go
5
star
25

etherman

Etherman is a CLI tool for managing and testing Solidity contract deployments, written in pure Go.
Go
5
star
26

midievent

Package midievent provides MIDI event type mappings for Go-lang.
Go
4
star
27

termtables

A fork of long-gone apcera/termtables, because I liked it.
Go
4
star
28

smsru

Go-lang API bindings for sms.ru
Go
3
star
29

qml-kit

qml-kit is a bootstrapping template for Go/QML projects.
Go
3
star
30

ziptools

Package ziptools provides functionality to search through USA zip codes and cities in extremely fast way.
Go
3
star
31

clipboard

Clipboard for Go (go-qml applications, uses Qt)
C++
2
star
32

tpmmgd

My coursework 2013 - Modeling DEDS with timed Petri nets
JavaScript
2
star
33

wp8sdk-installer

A try to install Windows Phone 8 SDK under Windows 7
Ruby
1
star
34

libafrodite

Code completion engine for Vala language
Vala
1
star
35

nl80211

Generating Go constants from a C header example project.
C
1
star
36

chunked

A PoC service for chunked and encrypted file uploads.
JavaScript
1
star
37

beam-o

Fire a beam to teleport your files onto servers in distant galaxies.
Go
1
star
38

tun

Tun is a tool that serves files from the specified directory or a web resource.
Go
1
star
39

linmath

Go port of linmath.h β€” a small library for linear math as required for computer graphics.
Go
1
star
40

statsd_metrics

Common logic to report Go runtime and custom metrics to Telegraf/StatsD
Go
1
star
41

api

Package api is a helper that simplifies the process of REST APIs bindings creation in Go.
Go
1
star
42

invoker

Supercharged "exec.Cmd" helpers for asynchronous and thread-safe reading of StdOut and StdErr.
Go
1
star