{"record":{"id":"54e076202c7779f0","repo":"golang/go","slug":"goroot-not-found","errorCode":null,"errorMessage":"GOROOT not found","messagePattern":"GOROOT not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"misc/go_android_exec/main.go","lineNumber":508,"sourceCode":"\t\tgorootPath = runtime.GOROOT()\n\t\tif gorootPath != \"\" {\n\t\t\treturn\n\t\t}\n\n\t\t// runtime.GOROOT is empty — perhaps go_android_exec was built with\n\t\t// -trimpath and GOROOT is unset. Try 'go env GOROOT' as a fallback,\n\t\t// assuming that the 'go' command in $PATH is the correct one.\n\n\t\tcmd := exec.Command(\"go\", \"env\", \"GOROOT\")\n\t\tcmd.Stderr = os.Stderr\n\t\tout, err := cmd.Output()\n\t\tif err != nil {\n\t\t\tgorootErr = fmt.Errorf(\"%v: %w\", cmd, err)\n\t\t}\n\n\t\tgorootPath = string(bytes.TrimSpace(out))\n\t\tif gorootPath == \"\" {\n\t\t\tgorootErr = errors.New(\"GOROOT not found\")\n\t\t}\n\t})\n\n\treturn gorootPath, gorootErr\n}\n\nfunc goTool() (string, error) {\n\tgoroot, err := findGoroot()\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn filepath.Join(goroot, \"bin\", \"go\"), nil\n}\n\nvar (\n\tgorootOnce sync.Once\n\tgorootPath string\n\tgorootErr  error","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/misc/go_android_exec/main.go#L490-L526","documentation":"Returned by findGoroot in misc/go_android_exec/main.go when both runtime.GOROOT() returns empty (binary built with -trimpath or GOROOT unset at build time) and the fallback `go env GOROOT` also returns empty. Without a GOROOT path, the tool cannot locate bin/go to drive the cross-build, so it aborts.","triggerScenarios":"go_android_exec binary built with -trimpath and no `go` on $PATH; running in an environment where the `go` binary is absent or not on PATH (stripped container, minimal docker image); PATH misconfigured so `go env GOROOT` fails or returns empty.","commonSituations":"CI image that ships go_android_exec built with -trimpath but does not include a go toolchain on PATH; distroless containers; developers using asdf/gvm where the go shim is not active in the subprocess; running the binary standalone outside a Go installation.","solutions":["Ensure a Go toolchain is installed and `go` is on $PATH: `which go` must succeed before running go_android_exec.","Set the GOROOT environment variable explicitly: export GOROOT=/usr/local/go (or the install path).","Rebuild go_android_exec without -trimpath so runtime.GOROOT() returns the build-time path.","If using a version manager (asdf/gvm), activate the Go shim in the same shell that runs go_android_exec."],"exampleFix":"# before\ngo run misc/go_android_exec/main.go # binary built -trimpath, no go on PATH -> throws\n\n# after\nexport PATH=\"/usr/local/go/bin:$PATH\"\nexport GOROOT=\"$(go env GOROOT)\"\ngo run misc/go_android_exec/main.go","handlingStrategy":"validation","validationCode":"if goroot, err := exec.Command(\"go\", \"env\", \"GOROOT\").Output(); err != nil || strings.TrimSpace(string(goroot)) == \"\" {\n  log.Fatal(\"GOROOT not found: install Go or set GOROOT env var\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure a Go toolchain is on $PATH (`which go` must succeed).","Set GOROOT explicitly in CI environments that build go_android_exec with -trimpath.","Activate version-manager shims (asdf/gvm) in the shell that runs the tool."],"tags":["go","android","goroot","environment","path","trimpath","toolchain"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}