Gomobile工具链已过时,只能在Android Studio中使用。

huangapple go评论79阅读模式
英文:

Gomobile toolchain out of date, only in Android Studio

问题

我正在使用最新的gomobile、Go和Android Studio版本。

当我在终端中运行gradle任务时,它们按预期工作并构建正确的二进制文件,但是在Android Studio中,我收到一个错误:

bin/gomobile: 工具链过时,请运行`gomobile init`

当然,我已经多次重新运行了gomobile init,但没有任何变化。我的假设是Android Studio正在使用一些我无法识别的配置。

我知道这是一个比较特殊的问题,但如果有人能指点我正确的方向,那将非常有帮助。

简而言之:./gradlew myproj:bind在终端中正常工作,在Android Studio中失败。

英文:

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.

答案1

得分: 1

我已经找到了这个问题的根源,以防其他人也遇到同样的问题;

  1. 对我来说,似乎 Gradle 插件没有正确识别 GO bin 的位置。相反,它使用以下方式查找 gobin;

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

我安装了多个 Go 版本(出于各种原因),所以我强制指定 gobin 失败了。为了发现这个问题,我在 env.go 文件中添加了调试日志。总的来说,当尝试调试时,该文件上的日志记录并不是最清晰的。

英文:

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.

答案2

得分: 0

这似乎是一个gomobile的错误信息,出现在cmd/gomobile/env.go#L69-L83中:

// 查找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`")
}

因此,请在本地会话和Android Studio会话之间仔细检查GOPATH的值。
例如,查看这个旧的(2015年)线程,看看其中的评论是否仍然适用。

英文:

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.

huangapple
  • 本文由 发表于 2017年2月26日 09:37:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/42463743.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定