1

I am working with the latest gomobile, Go, and Android Studio builds.

When I run the gradle tasks from the terminal they work as expected and build the correct binaries, however from within Android Studio I receive an error:

bin/gomobile: toolchain out of date, run `gomobile init`

Of course I have re run gomobile init many times and no change. My assumption is that Android Studio is using some config that I can not identify.

I appreciate this is a somewhat edge case question, but if anyone can point me in the right direction it would be helpful.

TLDR; ./gradlew myproj:bind works fine in terminal, fails in Android Studio.

saurabh
  • 724
  • 3
  • 17
Steve
  • 469
  • 4
  • 12

2 Answers2

1

I have gotten to the bottom of this in case anyone else has the issue;

  1. It appears, at least for me, the Gradle plugin wasn't respecting the location of the GO bin. Instead it looks up the gobin using;

            gobin, err := exec.LookPath("go")
    

I have a number of Go versions installed (for various reasons) so my forcing the gobin was failing. To discover this I have added debug logs to the env.go file. In general the logging on the file is not the most clear when attempting to debug.

Steve
  • 469
  • 4
  • 12
0

This seems to be a gomobile error message, seen in cmd/gomobile/env.go#L69-L83:

// Find gomobilepath.
gopath := goEnv("GOPATH")
for _, p := range filepath.SplitList(gopath) {
    gomobilepath = filepath.Join(p, "pkg", "gomobile")
    if _, err := os.Stat(gomobilepath); buildN || err == nil {
        break
    }
}

verpath := filepath.Join(gomobilepath, "version")
installedVersion, err := ioutil.ReadFile(verpath)
if !bytes.Equal(installedVersion, version) {
    return nil, errors.New("toolchain out of date, run `gomobile init`")
}

So double-check the value of GOPATH between your local session and your Android Studio session.
See for instance this old (2015) thread to see if any of those comments still apply.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Plus Go 1.8 might have fixed https://github.com/golang/go/issues/17996, with https://go-review.googlesource.com/#/c/33372/2//COMMIT_MSG – VonC Feb 26 '17 at 01:46
  • Thanks both. The GOPATH *should* be extracted from the org.golang.mobile.bind plugin, in fact when I remove my GOPATH from my profile, the terminal function still works as it is extracted. – Steve Feb 26 '17 at 02:30
  • I believe that change was focussed on correcting the incorrect example, not actual functionality. (i.e. The example does not have an "=") – Steve Feb 26 '17 at 02:31