no Android NDK found in $ANDROID_HOME/ndk-bundle nor in $ANDROID_NDK_HOME in Ubuntu 18.04

2.1k Views Asked by At

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.

1

There are 1 best solutions below

0
On

What worked for me when facing a similar issue was to.

  1. Make sure the ndk-bundle folder exists in

/Users/username/Library/Android/sdk

  1. run this

export ANDROID_NDK_HOME=/Users/username/Library/Android/sdk

  1. run your

gomobile build -target android hello.go