cmd/gomobile: improve NDK version detection

Look for the compiler directly, not just the existence of the
directory containing.

Fixes golang/go#30637

Change-Id: Iae4429406da8622e7085bf3701c0f84d5c95d2fd
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/165937
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/cmd/gomobile/env.go b/cmd/gomobile/env.go
index 504c61a..b432006 100644
--- a/cmd/gomobile/env.go
+++ b/cmd/gomobile/env.go
@@ -85,10 +85,17 @@
 	if ndkRoot, err := ndkRoot(); err == nil {
 		androidEnv = make(map[string][]string)
 		for arch, toolchain := range ndk {
+			clang := toolchain.Path(ndkRoot, "clang")
+			if !buildN {
+				_, err = os.Stat(clang)
+				if err != nil {
+					return fmt.Errorf("No compiler for %s was found in the NDK (tried %q). Make sure your NDK version is >= r19b. Use `sdkmanager --update` to update it.", arch, clang)
+				}
+			}
 			androidEnv[arch] = []string{
 				"GOOS=android",
 				"GOARCH=" + arch,
-				"CC=" + toolchain.Path(ndkRoot, "clang"),
+				"CC=" + clang,
 				"CXX=" + toolchain.Path(ndkRoot, "clang++"),
 				"CGO_ENABLED=1",
 			}
@@ -153,11 +160,6 @@
 	if err != nil {
 		return "", fmt.Errorf("The NDK was not found in $ANDROID_HOME/ndk-bundle (%q). Install the NDK with `sdkmanager 'ndk-bundle'`", ndkRoot)
 	}
-	prebuiltPath := filepath.Join(androidHome, "ndk-bundle", "toolchains", "llvm", "prebuilt")
-	_, err = os.Stat(prebuiltPath)
-	if err != nil {
-		return "", fmt.Errorf("No prebuilt toolchains found in $ANDROID_HOME/ndk-bundle/toolchains/llvm/prebuilt (%q). Make sure your NDK version is >= r19b. Use `sdkmanager --update` to update it.", prebuiltPath)
-	}
 	return ndkRoot, nil
 }