I'm trying to compile native GO code for android with gomobile. Looks like gomobile is not finding ndk-build.
gomobile build -target android hello.go gomobile: no Android NDK found in $ANDROID_HOME/ndk-bundle nor in $ANDROID_NDK_HOME
I've installed Android NDK in the ANDROID_HOME directory, changed permission on the folder to 777 and added an export entry in ~/.profile as below.
echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/root/work/bin:/root/ANDROID_HOME/android-ndk-r21/ndk-build
I installed gomobile from "https://godoc.org/golang.org/x/mobile/cmd/gomobile" as: go get golang.org/x/mobile/cmd/gomobile
"gomobile init" executes without issue; however "gomobile bind" gives the same error mesage as the gomobile build error.
I've even tried to set the env variable in the "/work/src/golang.org/x/mobile/cmd/gomobile/env.go" file as below, yet the os.GetEnv call returns blank.
os.Setenv("ANDROID_HOME", "/home/usr/ANDROID_HOME/ndk-bundle/android-ndk-r21/ndk-build")
androidHome := os.Getenv("ANDROID_HOME")
if androidHome != "" {
ndkRoot := filepath.Join(androidHome, "ndk-bundle")
_, err := os.Stat(ndkRoot)
if err == nil {
return ndkRoot, nil
}
}
The build fails no matter I run it in Ubuntu 18.04 vm or a docker container. Appreciate input and feedback.
Thanks for reading.
What worked for me when facing a similar issue was to.