Skip to content

mahsanet/gomobile

 
 

Repository files navigation

Go support for Mobile devices

Go Reference

The Go mobile repository holds packages and build tools for using Go on mobile platforms.

Package documentation as a starting point:

Caution image

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.

Using multiple gomobile AARs in one app

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.

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Go 86.3%
  • Objective-C 4.8%
  • Java 4.8%
  • C 3.7%
  • Other 0.4%