After trying $ANDROID_HOME/ndk-bundle, we also try $ANDROID_NDK_HOME. ANDROID_NDK_HOME is advised in this NDK sample code wiki: https://github.com/googlesamples/android-ndk/wiki Mentioned in the Bazel buildsystem Android app tutorial: https://docs.bazel.build/versions/master/tutorial/android-app.html On Ubuntu, the google-android-ndk-installer leaves the NDK in /usr/lib/android-ndk, and it seems to be up to the user to set ANDROID_NDK_HOME. On Arch Linux, the android-ndk package installs the NDK into /opt/android-ndk and sets ANDROID_NDK_HOME to there using an /etc/profile.d/file Fixes golang/go#31461 Change-Id: I9f7f7e24b19e0047419f9725b67bd6daf2b1d328 Reviewed-on: https://go-review.googlesource.com/c/mobile/+/171938 Run-TryBot: Elias Naur <mail@eliasnaur.com> Reviewed-by: Elias Naur <mail@eliasnaur.com>
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestNdkRoot(t *testing.T) {
|
|
home, err := ioutil.TempDir("", "gomobile-test-")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
homeorig := os.Getenv("ANDROID_HOME")
|
|
ndkhomeorig := os.Getenv("ANDROID_NDK_HOME")
|
|
defer func() {
|
|
os.Setenv("ANDROID_HOME", homeorig)
|
|
os.Setenv("ANDROID_NDK_HOME", ndkhomeorig)
|
|
os.RemoveAll(home)
|
|
}()
|
|
|
|
os.Setenv("ANDROID_HOME", home)
|
|
|
|
if ndk, err := ndkRoot(); err == nil {
|
|
t.Errorf("expected error but got %q", ndk)
|
|
}
|
|
|
|
sdkNDK := filepath.Join(home, "ndk-bundle")
|
|
envNDK := filepath.Join(home, "android-ndk")
|
|
|
|
for _, dir := range []string{sdkNDK, envNDK} {
|
|
if err := os.Mkdir(dir, 0755); err != nil {
|
|
t.Fatalf("couldn't mkdir %q", dir)
|
|
}
|
|
}
|
|
|
|
os.Setenv("ANDROID_NDK_HOME", envNDK)
|
|
|
|
if ndk, _ := ndkRoot(); ndk != sdkNDK {
|
|
t.Errorf("got %q want %q", ndk, sdkNDK)
|
|
}
|
|
|
|
os.Unsetenv("ANDROID_HOME")
|
|
|
|
if ndk, _ := ndkRoot(); ndk != envNDK {
|
|
t.Errorf("got %q want %q", ndk, envNDK)
|
|
}
|
|
|
|
os.RemoveAll(envNDK)
|
|
|
|
if ndk, err := ndkRoot(); err == nil {
|
|
t.Errorf("expected error but got %q", ndk)
|
|
}
|
|
|
|
os.Setenv("ANDROID_HOME", home)
|
|
|
|
if ndk, _ := ndkRoot(); ndk != sdkNDK {
|
|
t.Errorf("got %q want %q", ndk, sdkNDK)
|
|
}
|
|
}
|