The Go mobile repository holds packages and build tools for using Go on mobile platforms.
Package documentation as a starting point:
The Go Mobile project is experimental. Use this at your own risk. While we are working hard to improve it, neither Google nor the Go team can provide end-user support.
By default, gomobile bind for Android emits an AAR containing
jni/<abi>/libgojni.so and Java runtime support classes in the go
package. If two independently built gomobile AARs are added to the same
Android app, those shared names collide.
When you control all of the Go packages, prefer building them together:
$ gomobile bind -target=android -o all.aar example.com/auth example.com/payments
For AARs that must be built and consumed independently, pass a distinct
-soname for each build. The value must match [a-zA-Z][a-zA-Z0-9_]*.
$ gomobile bind -target=android -soname gojni_auth -o auth.aar example.com/auth
$ gomobile bind -target=android -soname gojni_payments -o payments.aar example.com/payments
This produces shared libraries such as libgojni_auth.so and namespaces
the generated JNI/runtime support symbols and classes so the AARs can be
packaged together without Android Gradle packagingOptions workarounds.
If -javapkg is set and -soname is omitted, gomobile derives a soname
automatically by replacing dots with underscores and prepending gojni_.
For example, -javapkg com.corp.auth derives gojni_com_corp_auth.
Each independently built AAR still contains its own Go runtime instance. That avoids name collisions, but it also means each AAR has separate memory, goroutine, and initialization overhead.
This is early work and installing the build system requires Go 1.5. Follow the instructions on golang.org/wiki/Mobile to install the gomobile command, build the basic and the bind example apps.
--
Contributions to Go are appreciated. See https://go.dev/doc/contribute.
The git repository is https://go.googlesource.com/mobile.
- Bugs can be filed at the Go issue tracker.
- Feature requests should preliminary be discussed on golang-nuts mailing list.
