Compiling within Android for Android

752 views
Skip to first unread message

Dorival

unread,
Oct 25, 2011, 11:48:30 PM10/25/11
to golang-nuts
Hi, I was just wondering if anyone tried to compile a Go Hello World
app in Android for Android? Well, I reckon we would have to compile Go
in Android first. That'd be great since I could work (play with
programming using Go) on my Asus Transformer during, say, a flight.
Cheers. Dorival

Brad Fitzpatrick

unread,
Oct 26, 2011, 12:42:13 AM10/26/11
to Dorival, golang-nuts
One of our ARM buildbots is running on a Xoom.  (compiling on it, too, the whole thing)  Admittedly it's a Xoom with a Debian userspace running parallel to the Android userspace, though.

I imagine you could put all the binaries in the right places and it'd work without the Debian userspace, though.  Haven't tried.

You can build it all on your x86 machine and then adb push over the 5g, 5l and linux_arm/../*.a files and try it out and let us know!

Message has been deleted

Dorival

unread,
Oct 26, 2011, 3:09:30 AM10/26/11
to golang-nuts
Thanks a lot for your reply.

Yes, I've played around with the Debian userspace before but was
looking for something "lighter".

The option of cross-compiling 5g/l sounds interesting; I've tried this
without success though. In my Ubuntu 11.10-x86 I've tried to compile
Go using both:

1) arm-linux-gnueabi-gcc (from sudo apt-get install gcc-arm-linux-
gnueabi); and

2) arm-linux-androideabi-gcc (from Android NDK R6b with a standalone
toolchain)

A simple Hello World in C runs fine with option (2) but not (1).

After changing make.bash (only) by replacing#CC=${CC:-gcc}withCC=$HOME/
pkg/android-mytoolchain/bin/arm-linux-androideabi-gccThe compilation
of Go (./all.bash) stops with the following message:

%%%% making lib9 %%%%make: Entering directory `/home/dorival/pkg/
go_arm/src/lib9'quietgcc -I"/home/dorival/pkg/go_arm/include" -ggdb -
O2 -c "/home/dorival/pkg/go_arm/src/lib9/_p9dir.c"...quietgcc -I"/home/
dorival/pkg/go_arm/include" -ggdb -O2 -c "/home/dorival/pkg/go_arm/src/
lib9/dup.c"cc1: warnings being treated as errors/home/dorival/pkg/
go_arm/src/lib9/dirfwstat.c:75: error: implicit declaration of
function 'futimes'

Any hints are highly appreciated.

Dorival

unread,
Oct 26, 2011, 4:59:02 AM10/26/11
to golan...@googlegroups.com
I've succeeded on cross-compiling 5g and 5l for Android ARM.

1) To get around the "go_arm/src/lib9/dirfwstat.c:75: error: implicit declaration of 
function 'futimes'" error I've removed the key -Werror from quietgcc.bash

2) I don't know why but by calling ./all.bash only 5l gets compiled. But by cd cmd and then make, 5g gets compiled.

Well, 5g works on my Android tablet; however I still have to figure out how to "adb push" the source tree in order to solve dependencies issues.

I'm getting the following error during compilation (in Android):

./5g hello.go

hello.go:4: can't find import: fmt

It's looking good :-)
cheers.

Dave Cheney

unread,
Oct 26, 2011, 5:05:05 AM10/26/11
to golan...@googlegroups.com
> I'm getting the following error during compilation (in Android):
> ./5g hello.go
> hello.go:4: can't find import: fmt

Awesome work, check that you have GOROOT, GOOS and GOARCH defined.

Brad Fitzpatrick

unread,
Oct 26, 2011, 10:44:28 AM10/26/11
to golan...@googlegroups.com
In $GOROOT/src, just run ./all-qemu.bash after apt-get install qemu-kvm-extras-static.

Then:
 adb mkdir /data/local/go     (iirc)
 adb push $GOROOT/ /data/local/go/

And set your environment variables on the Android device, like Dave was saying.

Dorival

unread,
Oct 27, 2011, 7:06:28 AM10/27/11
to golan...@googlegroups.com
Well, I've tried this without success...

I've declared GOROOT=/data/local/go and GOARCH=arm on the Android device, in addition to upload the whole $GOROOT.

5g still cannot find fmt ...

Also, I don't see difference when using all-quemu.bash since I still have to "cd cmd" & "make" to get 5g compiled. 

I guess I'm stuck now...
Cheers

uki

unread,
Oct 27, 2011, 9:14:14 AM10/27/11
to golan...@googlegroups.com
I had a simmilar error when using a different shell/coreutils.
Maybe try to install busybox first?

Łukasz Gruner

2011/10/27 Dorival <dorival...@gmail.com>:

Dorival

unread,
Oct 28, 2011, 8:41:58 PM10/28/11
to golan...@googlegroups.com
Well, I have busybox but don't see how it would solve the problem...

Another question: Go is written in C, right? then all the files in pkg are compiled by Go. So, I think my problem is that I don't know how to set the "qemu" during the cross-compilation. I at least I could split both compilations stages... Well I'll try this again later.

Cheers and thanks for the feedback.
Dorival
Reply all
Reply to author
Forward
0 new messages