golang/go · error
failed to locate cmd/go for target platform
Error message
failed to locate cmd/go for target platform
What it means
Returned by go_android_exec (misc/go_android_exec/main.go) when `go list -f {{.Target}} cmd/go` succeeds but reports an empty/relative path, meaning the cross-compile target binary was not built. The tool needs the platform-native go binary to push to the Android device; if cmd/go was not built for GOOS=android GOARCH=arm64 (or similar), {{.Target}} resolves to '.' and the push step has nothing to copy.
Source
Thrown at misc/go_android_exec/main.go:431
if len(bytes.TrimSpace(out)) > 0 {
log.Printf("\n%s", out)
}
return fmt.Errorf("%v: %w", cmd, err)
}
if err := adb("exec-out", "mkdir", "-p", deviceGoroot); err != nil {
return err
}
// Copy the Android tools from the relevant bin subdirectory to GOROOT/bin.
cmd = exec.Command(goTool, "list", "-f", "{{.Target}}", "cmd/go")
cmd.Stderr = os.Stderr
out, err = cmd.Output()
if err != nil {
return fmt.Errorf("%v: %w", cmd, err)
}
platformBin := filepath.Dir(string(bytes.TrimSpace(out)))
if platformBin == "." {
return errors.New("failed to locate cmd/go for target platform")
}
if err := adb("push", platformBin, path.Join(deviceGoroot, "bin")); err != nil {
return err
}
// Copy only the relevant subdirectories from pkg: pkg/include and the
// platform-native binaries in pkg/tool.
if err := adb("exec-out", "mkdir", "-p", path.Join(deviceGoroot, "pkg", "tool")); err != nil {
return err
}
if err := adb("push", filepath.Join(goroot, "pkg", "include"), path.Join(deviceGoroot, "pkg", "include")); err != nil {
return err
}
cmd = exec.Command(goTool, "list", "-f", "{{.Target}}", "cmd/compile")
cmd.Stderr = os.Stderr
out, err = cmd.Output()
if err != nil {View on GitHub (pinned to b6b368adc5)
Solutions
- Build the android-targeted toolchain first: GOOS=android GOARCH=arm64 go install cmd/go (repeat per target arch).
- Verify with GOOS=android GOARCH=arm64 go list -f {{.Target}} cmd/go — it must print an absolute path under pkg/tool/android_arm64, not '.'.
- Ensure GOOS/GOARCH/GOANDROID are exported in the environment that invokes go_android_exec, so `go list` resolves the correct target.
- Re-run `go install std cmd` for the android target to repopulate a trimmed GOROOT.
Example fix
# before
GOOS=android GOARCH=arm64 go run misc/go_android_exec/main.go ... # throws
# after
GOOS=android GOARCH=arm64 go install cmd/go cmd/compile
GOOS=android GOARCH=arm64 go list -f '{{.Target}}' cmd/go # sanity check
GOOS=android GOARCH=arm64 go run misc/go_android_exec/main.go ... Defensive patterns
Strategy: validation
Validate before calling
out, err := exec.Command("go", "list", "-f", "{{.Target}}", "cmd/go").Output()
if err != nil { log.Fatal(err) }
if dir := filepath.Dir(strings.TrimSpace(string(out))); dir == "." {
log.Fatal("run: GOOS=android GOARCH=<arch> go install cmd/go first")
} Prevention
- Always run `GOOS=android GOARCH=<arch> go install cmd/go cmd/compile` before invoking go_android_exec.
- Export GOOS/GOARCH/GOANDROID in the shell environment so `go list` resolves the target correctly.
- Verify the target path is absolute and under pkg/tool before invoking the tool.
When it happens
Trigger: Running `go run misc/go_android_exec/main.go` (or `go_android_exec` as the GOANDROID tool) without first building the android-targeted toolchain binaries; GOOS/GOARCH env not set so `go list` resolves to the host target whose Dir is '.'; stale or partial GOROOT where bin/<goos>_<goarch>/go is missing.
Common situations: First-time setup of Android cross-exec on a fresh GOROOT; CI images that did not run `go install cmd/go` for the android target; switching host OS without rebuilding cross toolchain; manually trimming GOROOT/bin.
Related errors
- failed to locate cmd/compile for target platform
- GOROOT not found
- globalThis.crypto is not available, polyfill required (crypt
- globalThis.performance is not available, polyfill required (
- globalThis.TextEncoder is not available, polyfill required
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/7d2ea9d32f1259e3.
Report an issue: GitHub.