Using go-mobile to build a native NDK with Go. On Windows.

Richard Porteous

This is meant to be Notes to supplement the instructions online at the relevant sites. Not everything was obvious or easy to find so I created these “rough” notes to help me. Oh and if you see ‘ratp’ in your path change if for your windows user home path name.

Some companies force a 24 hour delay to enable developer on an Android device, so do this right away if you plan on using a real device!

Prerequisite

git for windows

go compiler

adb (android debug) ~ this may be automatic or you’ll be prompted

windows explorer (the file browser) need to change the view/show change to show file name extensions and hidden items

Get started

I found my first success with this by doing the following.

You need to install the android SDK and NDK. Download and Install android studio or the cmd line tools (from the same web-page)

The ANDROID_HOME and ANDROID_NDK_HOME environment variables can be used to specify the Android SDK and NDK if they are not in the default locations. ANDROID_NDK_HOME needs the path up to the ndk plus the version number

mine looks like


ANDROID_HOME=C:\Users\ratpa\AppData\Local\Android\Sdk

ANDROID_NDK_HOME=C:\Users\ratpa\AppData\Local\Android\Sdk\ndk\27.3.13750724

And because windows relies on services to keep it safe, You will have to add exceptions to Windows Security.

If you plan on testing on a real device you will need it in Developer options in settings by tapping build several times. Go into options, use usb debugging or Wireless debugging. Uncheck Verify bytecode of debuggable apps.

Create a project

go to a folder dedicated to this


mkdir basic

cd basic

go mod init com.example.basic

To Install gomobile


go get golang.org/x/mobile

go install golang.org/x/mobile/cmd/gomobile@latest

gomobile init

You should have

several files in your project folder including at least 1 go file

Prepare


go mod tidy

build


gomobile build -androidapi 24 -target=android .

adb install --bypass-low-target-sdk-block basic.apk

you may or may-not need the bypass flag.

Final

Good Luck