Attemping a native Go android app, running into gobind error

426 views
Skip to first unread message

d...@mindstab.net

unread,
Jun 24, 2017, 10:05:50 AM6/24/17
to golang-nuts
I am working on creating an android app entirely in go using the Java og bindings, as outlined in
https://github.com/golang/mobile/tree/master/example/reverse

I created a go project under my goroot and an android project in my ~/AndroidStuioProjects
I seem to have the configs right but I seem to have run into a problem

:app:gobindDebug
2017/06/23 18:10:03 failed to go install the generated Java wrappers: exit status 2: go: cannot find GOROOT directory: /usr/local/go

 FAILED

FAILURE
: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:gobindDebug'.
> Process 'command '/home/user/src/go/bin/gobind'' finished with non-zero exit value 1



Which as far as I can tell if caused by
https://github.com/golang/go/issues/18209 [x/mobile: gobind ignores $GOROOT]


The only options I see are
1) put in a very hacky symlink
2) actually look at solving the bug

Anyone else see an option I'm missing?

Dan Ballard

unread,
Jun 25, 2017, 10:23:55 PM6/25/17
to golang-nuts
Well, the fix to gobind was simple, just add GOROOT to the env of cmds being execued
https://github.com/dballard/mobile/commit/ff01053d86dfbd6f8699e82b06e762c14ea269bd
Tho actually contributing it back seems like a chore, signing up to the golang entierly specific workflow. So maybe that'll be a job for anotehr day :/

Now however I am getting a gomobile failire

:app:gomobileDebug
/home/user/src/go/bin/gomobile: loadExportData failed go install -pkgdir=/home/user/src/go/pkg/gomobile/pkg_android_arm -gcflags=-shared -ldflags=-shared github.com/dballard/go-ricochet-mobile failed: exit status 1
../../../src/go/src/github.com/dballard/go-ricochet-mobile/InitActivity.go:12:2: cannot find package "Java/RicochetMobile/ActivityInitBinding" in any of:
   
/home/user/go/src/Java/RicochetMobile/ActivityInitBinding (from $GOROOT)
   
/tmp/gomobile-work-829567560/gen/src/Java/RicochetMobile/ActivityInitBinding (from $GOPATH)
   
/home/user/src/go/src/Java/RicochetMobile/ActivityInitBinding
../../../src/go/src/github.com/dballard/go-ricochet-mobile/InitActivity.go:10:2: cannot find package "Java/RicochetMobile/R/layout" in any of:
   
/home/user/go/src/Java/RicochetMobile/R/layout (from $GOROOT)
   
/tmp/gomobile-work-829567560/gen/src/Java/RicochetMobile/R/layout (from $GOPATH)
   
/home/user/src/go/src/Java/RicochetMobile/R/layout
../../../src/go/src/github.com/dballard/go-ricochet-mobile/InitActivity.go:6:2: cannot find package "Java/android/databinding/DataBindingUtil" in any of:
   
/home/user/go/src/Java/android/databinding/DataBindingUtil (from $GOROOT)
   
/tmp/gomobile-work-829567560/gen/src/Java/android/databinding/DataBindingUtil (from $GOPATH)
   
/home/user/src/go/src/Java/android/databinding/DataBindingUtil
../../../src/go/src/github.com/dballard/go-ricochet-mobile/InitActivity.go:7:2: cannot find package "Java/android/os" in any of:
   
/home/user/go/src/Java/android/os (from $GOROOT)
   
/tmp/gomobile-work-829567560/gen/src/Java/android/os (from $GOPATH)
   
/home/user/src/go/src/Java/android/os


 FAILED

FAILURE
: Build failed with an exception.

It seems like half the imports I would expect to be there are not
Any ideas?

the ones that worked were:
    "Java/android/support/v7/app"
    gopkg "Java/RicochetMobile"
    "Java/RicochetMobile/databinding"

Dan Ballard

unread,
Jun 26, 2017, 3:10:48 AM6/26/17
to golang-nuts
well, that wasn't so much work, created a code review in gerrit for the gobind GOROOT issue
https://go-review.googlesource.com/c/46671/


On Saturday, June 24, 2017 at 7:05:50 AM UTC-7, Dan Ballard wrote:

Dan Ballard

unread,
Jun 26, 2017, 3:29:45 AM6/26/17
to golang-nuts
So one thing slowing me down a bit is that there don't seem to be doc for gobind reverse stuff, I'm just using AndroidStudio and the gobind gradle plugin to call it. I'm not sure how to invoke it manually to try and debug it easier, and it seems the documentation for
https://godoc.org/golang.org/x/mobile/cmd/gobind
should be updated with invocation examples?


On Saturday, June 24, 2017 at 7:05:50 AM UTC-7, Dan Ballard wrote:

Elias Naur

unread,
Jun 26, 2017, 5:49:23 AM6/26/17
to golang-nuts
Hi Dan,

The gomobile reverse mode is very experimental, much more so than regular gomobile bindings. When in trouble, you'll probably have most luck going back to a working state and then add imports and usages of the reverse packages one at a time.

Also, while the reverse bindings can be useful to access Java/Android APIs easily from Go, I don't think it's realistic to use the reverse bindings to create an Androi app in (close to) 100% Go. The fundamental road block I found was keeping track of references between Java and Go, making sure no reference cycles persisted. And even if you succeeded, there's still iOS.

I'm currently researching ways to create the UI natively in Go; I'm particularly interested in the way Flutter is designed.

 - elias
Reply all
Reply to author
Forward
0 new messages