{"record":{"id":"cbabc688f5d808e8","repo":"golang/go","slug":"failed-to-locate-cmd-compile-for-target-platform","errorCode":null,"errorMessage":"failed to locate cmd/compile for target platform","messagePattern":"failed to locate cmd/compile for target platform","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"misc/go_android_exec/main.go","lineNumber":454,"sourceCode":"\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 {\n\t\treturn fmt.Errorf(\"%v: %w\", cmd, err)\n\t}\n\tplatformToolDir := filepath.Dir(string(bytes.TrimSpace(out)))\n\tif platformToolDir == \".\" {\n\t\treturn errors.New(\"failed to locate cmd/compile for target platform\")\n\t}\n\trelToolDir, err := filepath.Rel(filepath.Join(goroot), platformToolDir)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif err := adb(\"push\", platformToolDir, path.Join(deviceGoroot, relToolDir)); err != nil {\n\t\treturn err\n\t}\n\n\t// Copy all other files from GOROOT.\n\tdirents, err := os.ReadDir(goroot)\n\tif err != nil {\n\t\treturn err\n\t}\n\tfor _, de := range dirents {\n\t\tswitch de.Name() {\n\t\tcase \"bin\", \"pkg\":\n\t\t\t// We already created GOROOT/bin and GOROOT/pkg above; skip those.","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/misc/go_android_exec/main.go#L436-L472","documentation":"Returned by go_android_exec when `go list -f {{.Target}} cmd/compile` resolves to a relative '.' path, meaning the cross-target compiler binary was not installed. The tool needs the platform's compile binary at pkg/tool/<goos>_<goarch>/ to push to the device; absence makes the relative path collapse to '.'.","triggerScenarios":"Running go_android_exec without `go install cmd/compile` for the android target; GOROOT/pkg/tool trimmed or never populated for android; GOOS/GOARCH unset so go list resolves the host compile whose filepath.Rel yields '.'.","commonSituations":"Fresh CI runners that only built host toolchain; partial `go install` that built cmd/go but not cmd/compile; manually stripped GOROOT/pkg/tool; switching GOARCH mid-build.","solutions":["Install the cross compiler: GOOS=android GOARCH=arm64 go install cmd/compile cmd/go.","Verify: GOOS=android GOARCH=arm64 go list -f {{.Target}} cmd/compile must print an absolute path ending in pkg/tool/android_arm64.","Ensure GOROOT/pkg/tool contains the android_<goarch> subdirectory; if not, run a full `go install std cmd` for the target.","Confirm GOOS/GOARCH are exported in the shell that runs go_android_exec."],"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/compile\nls \"$(go env GOROOT)/pkg/tool/android_arm64/compile\" # 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/compile\").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/compile first\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install the cross compiler: GOOS=android GOARCH=<arch> go install cmd/compile cmd/go.","Confirm GOROOT/pkg/tool/<goos>_<goarch>/compile exists before running go_android_exec.","Keep GOOS/GOARCH exported in the invoking shell."],"tags":["go","android","cross-compilation","toolchain","compiler","goroot"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}