Go Mobile

Smile Egbai 

Android developer @Paylater.ng

Background

  • Mobile support was frequently requested

  • Some users built their own Go binaries for Android with cgo + external linking through NDK tool chains
  • Examples (Perkeep android app & Goandroid+Mandala )

why?

  • Complete Go system (server/client)
  • Write a single cross-platform Go library

Native

  • Write the whole app in Go
  • Use Go packages for graphics, event handling, audio, etc.

SDK Apps

  • Write Android UI in kotlin/java, iOS UI in Objective-C/Swift
  • Write common functionality in Go as a library

Go native (golang.org/x/mobile/)

  • App control
  • Asset management
  • Open gl
  • Events
  • Screen geometry

SDK

go get golang.org/x/mobile/cmd/gobind

Bind basics

const DEBIT = "debit"


type Sms struct {
	/.../
}

func IsAccountAlert(value string) bool {
	/.../
	return alert
}

func IsDebit(body string) bool {
	return s.Contains(body, DEBIT)
}

func TagCategory(body string) string {
	/.../
	return ""
}
public static final String DEBIT = "debit";

public static native double getAmount(String body);

public static native String getCurrency(String body);

public static native String getDate(String body);

public static native boolean isAccountAlert(String value);

public static native boolean isDebit(String body);

public static native String tagCategory(String body);

gomobile bind -target=android|ios

result -> xyz.framework || xyz.aar

Result

THANKS

REFERENCES

  • GopherCon 2015 HanaKim
  • https://github.com/golang/go/wiki/Mobile

Go Mobile

By egbai mmumene

Go Mobile

  • 12