Go: “Hello, Android!”

Chatting to bradfitz this morning, he mentioned he was going to try using Go to do some scripting-style tasks on the Android platform.

It turns out getting Go running on an ARM-based Android phone is easy. First, build Go for linux/arm:

~/go$ hg update -r release 22 files updated, 0 files merged, 1 files removed, 0 files unresolved ~/go$ GOOS=linux ~/go$ GOARCH=arm ~/go$ cd src ~/go/src$ ./all.bash

For testing purposes, we’ll use the most trivial of all Go programs:

package main  func main() { println("Hello, Android!") }

Compile and link it (the ARM compiler and linker is called 5g/5l):

~$ 5g hello.go && 5l hello.5

This will produce a binary called 5.out, that we now need to transfer to the phone itself. To do this, enable USB debugging on the phone, plug it into your computer, and use the ‘adb’ tool from the Android SDK to upload the file:

~$ adb push 5.out /data/local/hellogo 1036 KB/s (155648 bytes in 0.146s)

Our binary will now be at /data/local/hellogo. Now we need to open a shell on the phone, and execute the program:

~$ adb shell $ data/local/hellogo Hello, Android!


About markjeee

Entrepreneur, Programmer, Run-Bike Athlete
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s