Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions cmd/gomobile/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,17 @@ func envInit() (err error) {
androidEnv[arch] = []string{
"GOOS=android",
"GOARCH=" + arch,
"CC=" + clang,
"CXX=" + clangpp,
"CGO_ENABLED=1",
}

// Only set CC/CXX if neither is provided in the current environment.
if os.Getenv("CC") == "" {
androidEnv[arch] = append(androidEnv[arch], "CC=" + clang)
}
if os.Getenv("CXX") == "" {
androidEnv[arch] = append(androidEnv[arch], "CXX=" + clangpp)
}

if arch == "arm" {
androidEnv[arch] = append(androidEnv[arch], "GOARM=7")
}
Expand Down Expand Up @@ -531,10 +538,20 @@ func archNDK() string {
// Android NDK does not contain arm64 toolchains (until and
// including NDK 23), use use x86_64 instead. See:
// https://github.com/android/ndk/issues/1299
//
// Some Android environments (e.g. Termux with a custom NDK) do
// provide an arm64 host toolchain. Detect Termux via PREFIX and
// use the arm64 host toolchain in that case.
if runtime.GOOS == "darwin" {
arch = "x86_64"
break
}
if runtime.GOOS == "android" && strings.Contains(os.Getenv("PREFIX"), "com.termux") {
if _, err := os.Stat("/data/data/com.termux/files/usr/bin/clang"); err == nil {
arch = "arm64"
break
}
}
fallthrough
default:
panic("unsupported GOARCH: " + runtime.GOARCH)
Expand Down