How to build the go mobile example

1,658 views
Skip to first unread message

Zhou Amrita

unread,
Dec 13, 2014, 2:13:30 AM12/13/14
to golan...@googlegroups.com

my go version is go version go1.4 darwin/amd64
I clone the go/mobile repo and build it using docker:

go get -d golang.org/x/mobile/...
docker build -t mobile $GOPATH/src/golang.org/x/mobile

and I want to build the example/basic using this command as you show in README:

docker run -v $GOPATH/src:/src mobile /bin/bash -c 'cd example/basic && ./make.bash'

and it just output

/bin/bash: line 0: cd: example/basic: No such file or directory

but at this time I'm under golang.org/x/mobile directly.

and if I execute make.bash in the example/basic:

./make.bash
go build runtime: android/arm must be bootstrapped using make.bash

so how should I build this example?

Jason Playne

unread,
Dec 13, 2014, 2:27:17 AM12/13/14
to Zhou Amrita, golang-nuts
I cannot say what command you are exactly after, but if you are cross compiling you will need to have the go src you are using to compile ready for it.

Under linux I have my install in /usr/local/go...

to get ready for an arm/linux cross compile I use the following commands


cd /usr/local/go/src

GOARCH=arm GOARM=7 GOOS=linux ./make.bash


If you want to cross compile for android, then you will need the android development kit, you can follow the instructions on my blog



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zhou Amrita

unread,
Dec 13, 2014, 8:10:29 AM12/13/14
to golan...@googlegroups.com, okon...@gmail.com
thanks, the second command is this build script in the mobile package example:
https://github.com/golang/mobile/blob/master/example/basic/make.bash

but it seem that I need to download the golang source?

在 2014年12月13日星期六UTC+8下午3时27分17秒,Jason Playne写道:

David Crawshaw

unread,
Dec 13, 2014, 11:05:15 AM12/13/14
to Zhou Amrita, golang-nuts
I just tried deleting my docker image, making sure the mobile
repository was clean and then running the commands you did:

docker build -t mobile $GOPATH/src/golang.org/x/mobile
docker run -v $GOPATH/src:/src mobile /bin/bash -c 'cd example/basic
&& ./make.bash'

The result was:

BUILD SUCCESSFUL
Total time: 3 seconds

and a binary where I would expect it.

Could there be something unusual about your docker container? Or
perhaps your version of docker does not support the -v flag? I appear
to be running Docker 1.3.1. You might want to try

docker run -v $GOPATH/src:/src mobile /bin/bash -c pwd

I would expect to see /src/golang.org/x/mobile, and similarly:

docker run -v $GOPATH/src:/src mobile /bin/bash -c 'ls example/'
basic
libhello
libhellojni
sprite

Zhou Amrita

unread,
Dec 14, 2014, 12:43:52 AM12/14/14
to golan...@googlegroups.com, okon...@gmail.com
thanks, my docker version is too old, after upgrade to 1.3.2, I build this basic sample successfully, but after I install it my device, it immediately crash:
12-14 13:37:41.590 I/ActivityManager(  746): Start proc com.example.basic for activity com.example.basic/android.app.NativeActivity: pid=26356 uid=10335 gids={50335, 9997} abi=armeabi
12-14 13:37:41.602 I/art     (26356): Late-enabling -Xcheck:jni
12-14 13:37:41.658 W/linker  (26356): libbasic.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
12-14 13:37:41.691 I/Zygote  (  194): Process 26356 exited cleanly (2)
12-14 13:37:41.711 I/ActivityManager(  746): Process com.example.basic (pid 26356) has died
12-14 13:37:41.711 W/ActivityManager(  746): Force removing ActivityRecord{77f74a9 u0 com.example.basic/android.app.NativeActivity t2582}: app died, no saved state
12-14 13:37:41.717 W/WindowManager(  746): Failed looking up window
12-14 13:37:41.717 W/WindowManager(  746): java.lang.IllegalArgumentException: Requested window android.view.ViewRootImpl$W@2ab1b265 does not exist
12-14 13:37:41.717 W/WindowManager(  746): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8412)
12-14 13:37:41.717 W/WindowManager(  746): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8403)
12-14 13:37:41.717 W/WindowManager(  746): at com.android.server.wm.WindowManagerService.removeWindow(WindowManagerService.java:2558)
12-14 13:37:41.717 W/WindowManager(  746): at com.android.server.wm.Session.remove(Session.java:186)
12-14 13:37:41.717 W/WindowManager(  746): at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:2920)
12-14 13:37:41.717 W/WindowManager(  746): at android.view.ViewRootImpl.doDie(ViewRootImpl.java:5390)
12-14 13:37:41.717 W/WindowManager(  746): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3223)
12-14 13:37:41.717 W/WindowManager(  746): at android.os.Handler.dispatchMessage(Handler.java:102)
12-14 13:37:41.717 W/WindowManager(  746): at android.os.Looper.loop(Looper.java:135)
12-14 13:37:41.717 W/WindowManager(  746): at android.os.HandlerThread.run(HandlerThread.java:61)
12-14 13:37:41.717 W/WindowManager(  746): at com.android.server.ServiceThread.run(ServiceThread.java:46)
12-14 13:37:41.775 W/InputMethodManagerService(  746): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@2e394bf attribute=null, token = android.os.BinderProxy@393d769d
12-14 13:37:42.504 W/ActivityManager(  746): getTasks: caller 10163 does not hold GET_TASKS; limiting output

my device is nexus5 with android 5.0 

在 2014年12月14日星期日UTC+8上午12时05分15秒,David Crawshaw写道:

Bryan Turley

unread,
Dec 14, 2014, 12:56:49 AM12/14/14
to golan...@googlegroups.com, okon...@gmail.com


On Saturday, December 13, 2014 11:43:52 PM UTC-6, Zhou Amrita wrote:
thanks, my docker version is too old, after upgrade to 1.3.2, I build this basic sample successfully, but after I install it my device, it immediately crash:
12-14 13:37:41.590 I/ActivityManager(  746): Start proc com.example.basic for activity com.example.basic/android.app.NativeActivity: pid=26356 uid=10335 gids={50335, 9997} abi=armeabi
12-14 13:37:41.602 I/art     (26356): Late-enabling -Xcheck:jni
12-14 13:37:41.658 W/linker  (26356): libbasic.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
12-14 13:37:41.691 I/Zygote  (  194): Process 26356 exited cleanly (2)
12-14 13:37:41.711 I/ActivityManager(  746): Process com.example.basic (pid 26356) has died
12-14 13:37:41.711 W/ActivityManager(  746): Force removing ActivityRecord{77f74a9 u0 com.example.basic/android.app.NativeActivity t2582}: app died, no saved state
12-14 13:37:41.717 W/WindowManager(  746): Failed looking up window
12-14 13:37:41.717 W/WindowManager(  746): java.lang.IllegalArgumentException: Requested window android.view.ViewRootImpl$W@2ab1b265 does not exist
12-14 13:37:41.717 W/WindowManager(  746): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8412)
12-14 13:37:41.717 W/WindowManager(  746): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8403)
12-14 13:37:41.717 W/WindowManager(  746): at com.android.server.wm.WindowManagerService.removeWindow(WindowManagerService.java:2558)
12-14 13:37:41.717 W/WindowManager(  746): at com.android.server.wm.Session.remove(Session.java:186)
12-14 13:37:41.717 W/WindowManager(  746): at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:2920)
12-14 13:37:41.717 W/WindowManager(  746): at android.view.ViewRootImpl.doDie(ViewRootImpl.java:5390)
12-14 13:37:41.717 W/WindowManager(  746): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3223)
12-14 13:37:41.717 W/WindowManager(  746): at android.os.Handler.dispatchMessage(Handler.java:102)
12-14 13:37:41.717 W/WindowManager(  746): at android.os.Looper.loop(Looper.java:135)
12-14 13:37:41.717 W/WindowManager(  746): at android.os.HandlerThread.run(HandlerThread.java:61)
12-14 13:37:41.717 W/WindowManager(  746): at com.android.server.ServiceThread.run(ServiceThread.java:46)
12-14 13:37:41.775 W/InputMethodManagerService(  746): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@2e394bf attribute=null, token = android.os.BinderProxy@393d769d
12-14 13:37:42.504 W/ActivityManager(  746): getTasks: caller 10163 does not hold GET_TASKS; limiting output

my device is nexus5 with android 5.0 


Fairly certain this is a known problem with go on android5 (any device) and that they are working on it.


David Crawshaw

unread,
Dec 14, 2014, 11:52:50 AM12/14/14
to Bryan Turley, golang-nuts, Zhou Amrita
This is probably the issue Bryan mentions, filed as
https://golang.org/issue/9311. But I'm surprised there's no error
message in your log output. There should be if you built after
https://github.com/golang/go/commit/bee8ae11.

Bryan Turley

unread,
Dec 15, 2014, 1:33:48 PM12/15/14
to golan...@googlegroups.com, bryan...@gmail.com, okon...@gmail.com


On Sunday, December 14, 2014 10:52:50 AM UTC-6, David Crawshaw wrote:
This is probably the issue Bryan mentions, filed as
https://golang.org/issue/9311. But I'm surprised there's no error
message in your log output. There should be if you built after
https://github.com/golang/go/commit/bee8ae11.

That is the one.
 

philippe...@gmail.com

unread,
Feb 19, 2015, 8:54:51 PM2/19/15
to golan...@googlegroups.com, bryan...@gmail.com, okon...@gmail.com
Hi,
I seem to have the same problem on a Nexus 7, trying to build and then run the sample from golang.org/x/mobile/example/libhello/libhello
It runs fine if I built it from the docker image (docker pull golang/mobile)
But when I compile it myself the app crashes with similar logcat as mentioned above.

Ubuntu 14.10, Go 1.4.2, android-ndk-r10, running on Nexus 7
I read the reported issue/fix: https://github.com/golang/go/issues/9311, and was hoping that the fix would be applied in Go 1.4.2 ?

It seems to be a fix on src/runtime/malloc1.go which I don't even have in the sources of 1.4.2, so I can't apply it locally

thank you

David Crawshaw

unread,
Feb 20, 2015, 7:32:46 AM2/20/15
to philippe...@gmail.com, golang-nuts, Bryan Turley, Zhou Amrita
For now I would recommend using tip. Shortly the gomobile tool will be
usable and I'll keep some out-of-band copy of tip for building android
apps until 1.5 is out.

philippe...@gmail.com

unread,
Feb 20, 2015, 11:38:30 AM2/20/15
to golan...@googlegroups.com, philippe...@gmail.com, bryan...@gmail.com, okon...@gmail.com
Ok thank you, I'll grab the latest Go dev sources.
And thank you for the work on Go mobile.

philippe...@gmail.com

unread,
Feb 20, 2015, 8:12:48 PM2/20/15
to golan...@googlegroups.com, philippe...@gmail.com, bryan...@gmail.com, okon...@gmail.com
Yep, it worked.
I was able to build / run a test app with Android Studio (and latest NDK) that calls the Go code (libgojni.so) from the libhello example,
thx again
Reply all
Reply to author
Forward
0 new messages