Go on Android?

4,547 views
Skip to first unread message

ptolomy23

unread,
Jan 3, 2012, 10:26:33 AM1/3/12
to golang-nuts
Has anyone successfully run Go on Android recently (without building on Android) and care to share instructions?
I tried (cross compilations) based on old instructions, and there were failures. I'll happily try again, but perhaps
someone gave give me reassurance that compiling for Android on x86 Darwin or Linux is possible.

Andy Balholm

unread,
Jan 3, 2012, 11:22:08 AM1/3/12
to golan...@googlegroups.com
I compiled a Hello, world program on Mac OS X and ran it on a Galaxy Tab 10.1. I haven't taken it farther at this point.

I checked out a copy of the Go source and compiled it with GOARCH=arm and GOOS=linux. Then I compiled and linked my program with 5g and 5l.

The resulting binary wouldn't run in the Android emulator or my T-Mobile Comet (neither supports all the instructions that 5g generates, apparently). But it ran fine on the Tab.

Yves Junqueira

unread,
Jan 3, 2012, 2:11:53 PM1/3/12
to ptolomy23, golang-nuts

It is definitely possible, just not very convenient to use. I've run a torrent/DHT node software and a minecraft server in android phones.

Real example, with instructions:

https://github.com/huin/chunkymonkey/blob/master/docs/android-server.md

minux

unread,
Jan 3, 2012, 2:26:28 PM1/3/12
to ptolomy23, golang-nuts
On Tue, Jan 3, 2012 at 11:26 PM, ptolomy23 <ptol...@gmail.com> wrote:
Has anyone successfully run Go on Android recently (without building on Android) and care to share instructions?
Are you talking about the compiled Go program or the Go compiler itself? They are drastically different.
Compiled Go program works on Android fine, as others have shown, and I use godoc on Android daily.
Go compiler itself should be possible to run on Android as well, but I just use a debian chroot to build them
natively, so I can't say whether android-ndk can compile them or not (though I think it should be possible,
they don't have much external dependencies, even libc.).

Guillermo Estrada

unread,
Mar 11, 2012, 4:35:58 AM3/11/12
to golan...@googlegroups.com, ptolomy23
I would love for a cross compile of the compiler for arm linux android devices. That way you can build android apps there. Anyone has instructions or something?

minux

unread,
Mar 11, 2012, 5:24:39 AM3/11/12
to Guillermo Estrada, golan...@googlegroups.com, ptolomy23


On Sun, Mar 11, 2012 at 4:35 PM, Guillermo Estrada <phro...@gmail.com> wrote:
I would love for a cross compile of the compiler for arm linux android devices. That way you can build android apps there. Anyone has instructions or something?
CGO_ENABLED=0 GOOS=linux GOARCH=arm ./make.bash

Then you will get a Linux/ARM cross toolchain (you don't need to have a arm cross gcc).

Mike Rosset

unread,
Mar 11, 2012, 2:05:22 PM3/11/12
to Guillermo Estrada, golan...@googlegroups.com, ptolomy23

If you just need to build arm binaries for android simply cross
compile to that GOOS/GOARCH, cross compiling with go is quite trivial.

If you want to build things on your android with gc then it really
depends on your android device. I'm going to assume you are using
something that is arm based possible a tablet, In that is the case the
best thing to do is to set up Debian arm chroot, and use that to build
the compiler etc.

I have built gc on arm natively without a chroot, however due to the
limitations of andriod's bionic libc, I use a detacted eglibc, and
replicating this proces right now is not practical. basically I used
the CLFS method for this.

minux

unread,
Mar 11, 2012, 2:17:10 PM3/11/12
to Mike Rosset, Guillermo Estrada, golan...@googlegroups.com, ptolomy23


On Mon, Mar 12, 2012 at 2:05 AM, Mike Rosset <mike....@gmail.com> wrote:
I have built gc on arm natively without a chroot, however due to the
limitations of andriod's bionic libc, I use a detacted eglibc, and
replicating this proces right now is not practical. basically I used
the CLFS method for this.
You can build all gcc compiled binaries statically, it's a lot easier.

Mike Rosset

unread,
Mar 11, 2012, 2:29:41 PM3/11/12
to minux, Guillermo Estrada, golan...@googlegroups.com, ptolomy23

That works, however not all things compile statically, not without a
lot of hacking.

minux

unread,
Mar 11, 2012, 3:29:52 PM3/11/12
to Mike Rosset, Guillermo Estrada, golan...@googlegroups.com, ptolomy23
Not all things compile statically? What can't be compiled statically in go toolchain?
I've already built a experimental Go distro for Android, my limited tests shows it can
work.

Mike Rosset

unread,
Mar 12, 2012, 6:46:55 AM3/12/12
to minux, Guillermo Estrada, golan...@googlegroups.com, ptolomy23

gcc and the go tool tool obviously will "probably" build statically.
However if you want to build anything more ie, git and python etc.
that is another story.

minux

unread,
Mar 12, 2012, 8:05:40 AM3/12/12
to Mike Rosset, Guillermo Estrada, golan...@googlegroups.com, ptolomy23
But Go distribution doesn't require them, even gcc is unnecessary, because
there is no cgo support for Android/ARM now.

Mike Rosset

unread,
Mar 12, 2012, 1:47:25 PM3/12/12
to minux, Guillermo Estrada, golan...@googlegroups.com, ptolomy23
> But Go distribution doesn't require them, even gcc is unnecessary, because
> there is no cgo support for Android/ARM now.

I guess I was not clear enough, if you make a *native* toolchain for
android and you want to build Go natively, that is fine. However if
you make a native toolchain it would stand to reason you plan on
building a lot more then Go in which case some software does not
inherently build statically (some not at all) .. so dynamically
linking ends up being more practical in this case.

Mike Rosset

unread,
Mar 12, 2012, 2:15:09 PM3/12/12
to Guillermo Estrada, golan...@googlegroups.com
On Mon, Mar 12, 2012 at 11:06 AM, Guillermo Estrada <phro...@gmail.com> wrote:
> It  compiles without errors and nicely. But I've tried almost anything i could imagine and I cant run the program. I keep getting "cannot execute - Permission Denied" even after setting permssion to 777 and trying to run as root.
>
> Any ideas?

Android has special permissions for mounts ie /sdcard will not allow
you to run executable's at all. try moving to /system/xbin but that
might require you to root the device.

Brandon Mercer

unread,
Mar 12, 2012, 2:39:45 PM3/12/12
to Mike Rosset, Guillermo Estrada, golan...@googlegroups.com
I have been running go on android on my tablet for some time now. It's
a pretty basic set of instructions... off the top of my head I did the
GOOS, GOHOST and built the toolchain statically because android isn't
quite exactly like linux and I couldn't make the android SDK stuff
build go so it was easy enough to do that. After that I just zip up
go/* and unzip it on the android device in /data/local/go, set some
paths and build things. I've been writing, compiling, running go on
android for a while now. ICS works fine too. Hope this is useful.
Brandon
Reply all
Reply to author
Forward
0 new messages