{"record":{"id":"7d2ea9d32f1259e3","repo":"golang/go","slug":"failed-to-locate-cmd-go-for-target-platform","errorCode":null,"errorMessage":"failed to locate cmd/go for target platform","messagePattern":"failed to locate cmd/go for target platform","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"misc/go_android_exec/main.go","lineNumber":431,"sourceCode":"\t\tif len(bytes.TrimSpace(out)) > 0 {\n\t\t\tlog.Printf(\"\\n%s\", out)\n\t\t}\n\t\treturn fmt.Errorf(\"%v: %w\", cmd, err)\n\t}\n\tif err := adb(\"exec-out\", \"mkdir\", \"-p\", deviceGoroot); err != nil {\n\t\treturn err\n\t}\n\n\t// Copy the Android tools from the relevant bin subdirectory to GOROOT/bin.\n\tcmd = exec.Command(goTool, \"list\", \"-f\", \"{{.Target}}\", \"cmd/go\")\n\tcmd.Stderr = os.Stderr\n\tout, err = cmd.Output()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%v: %w\", cmd, err)\n\t}\n\tplatformBin := filepath.Dir(string(bytes.TrimSpace(out)))\n\tif platformBin == \".\" {\n\t\treturn errors.New(\"failed to locate cmd/go for target platform\")\n\t}\n\tif err := adb(\"push\", platformBin, path.Join(deviceGoroot, \"bin\")); err != nil {\n\t\treturn err\n\t}\n\n\t// Copy only the relevant subdirectories from pkg: pkg/include and the\n\t// platform-native binaries in pkg/tool.\n\tif err := adb(\"exec-out\", \"mkdir\", \"-p\", path.Join(deviceGoroot, \"pkg\", \"tool\")); err != nil {\n\t\treturn err\n\t}\n\tif err := adb(\"push\", filepath.Join(goroot, \"pkg\", \"include\"), path.Join(deviceGoroot, \"pkg\", \"include\")); err != nil {\n\t\treturn err\n\t}\n\n\tcmd = exec.Command(goTool, \"list\", \"-f\", \"{{.Target}}\", \"cmd/compile\")\n\tcmd.Stderr = os.Stderr\n\tout, err = cmd.Output()\n\tif err != nil {","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/misc/go_android_exec/main.go#L413-L449","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nGOOS=android GOARCH=arm64 go run misc/go_android_exec/main.go ... # throws\n\n# after\nGOOS=android GOARCH=arm64 go install cmd/go cmd/compile\nGOOS=android GOARCH=arm64 go list -f '{{.Target}}' cmd/go # sanity check\nGOOS=android GOARCH=arm64 go run misc/go_android_exec/main.go ...","handlingStrategy":"validation","validationCode":"out, err := exec.Command(\"go\", \"list\", \"-f\", \"{{.Target}}\", \"cmd/go\").Output()\nif err != nil { log.Fatal(err) }\nif dir := filepath.Dir(strings.TrimSpace(string(out))); dir == \".\" {\n  log.Fatal(\"run: GOOS=android GOARCH=<arch> go install cmd/go first\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["go","android","cross-compilation","toolchain","goroot","environment"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}