Oh yeah, I should take some notes on my efforts. The past couple of weeks I’ve been messing with a side project of mine to modify Minecraft Pocket Edition worlds. My original intent was to use Go to compile executables to run on PC, Mac or Linux and copy the mobile game worlds off the device to edit them, then transfer them back. But apparently Go can do Android, too (with caveats).
So I decided to first do a “hello, world” or similar before seeing if my complex program can be made to run. That took much longer than I thought, even though I had Go installed and decided to use an example app with copy-paste instructions.
Here’s a review of my journey:
- Updated Go to a newer version
- I am not sure I need to as I had 1.5; apparently 1.7 is needed for Mac
- I relearned the hard way you have to uninstall the old Go before installing the new (no in-place upgrade)
- I messed up my GOROOT variable but fixed it
- Tried using these instructions to get an example Go app running on Android. (By “native” in this page they mean native Go, not native Android/iOS.) But had a few detours:
- Finally had to add GOPATH/bin to my PATH to make things easier
- In my stubbornness, I did not want to install Android Studio or the download manager, so I tried and eventually succeeded in installing just the command-line tools I need
- Downloaded just the command line tools from the very bottom of this page
- Unzipped to c:\tools\AndroidSDK\
sdkmanager "platforms;android-25"(I’m not entirely sure this was necessary for my needs tonight)
- Incidentally, I had to get Java working before
sdkmanagerwould work. I kind of hate Java being installed, so I just pointed JAVA_HOME to the JRE files.
- So I was finally ready to go back to the instructions from earlier:
gomobile init -ndk C:\tools\AndroidSDK\ndk-bundle\- This takes a while, and since I didn’t use the download manager/installer I had to use the
-ndkflag here to point to where I had the NDK installed. This. Took. For. Ever. I was cursing Java a lot while this ran.
go get golang.org/x/mobile/cmd/gomobile
gomobile build -a -target=android golang.org/x/mobile/example/basic- I added the
-acommand to the instructions’ command to rebuild everything to make sure I didn’t still have any messed-up cruft from the Go upgrade since I had previously tried to compile this and failed.
gomobile install golang.org/x/mobile/example/basic- Of course before running this I got the Android device hooked up via USB and USB debugging enabled. The instructions on enabling that is in the “Enable adb debugging on your device” section on this page. The first time I ran it there was a popup to accept on the device, and the PC side gave an error. After accepting and running again, the example app installed and worked!