From 66aae86d4025618ed0d27964d197fcaebc271b6d Mon Sep 17 00:00:00 2001 From: James Tucker Date: Mon, 4 Aug 2025 17:27:23 -0700 Subject: [PATCH] Makefile: move NDK_ROOT below ANDROID_HOME detection If ANDROID_HOME is being detected by the code that finds a valid home with an empty host environment, then NDK_ROOT should be able to use that, but it was out of order in the evaluation. Updates #cleanup Signed-off-by: James Tucker --- Makefile | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 342e0bc..ea93133 100644 --- a/Makefile +++ b/Makefile @@ -13,19 +13,6 @@ DOCKER_IMAGE := tailscale-android-build-amd64-041425-1 export TS_USE_TOOLCHAIN=1 -# Auto-select an NDK from ANDROID_HOME (choose highest version available) -NDK_ROOT ?= $(shell ls -1d $(ANDROID_HOME)/ndk/* 2>/dev/null | sort -V | tail -n 1) - -HOST_OS := $(shell uname | tr A-Z a-z) -ifeq ($(HOST_OS),linux) - STRIP_TOOL := $(NDK_ROOT)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-objcopy -else ifeq ($(HOST_OS),darwin) - STRIP_TOOL := $(NDK_ROOT)/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-objcopy -endif - -$(info Using NDK_ROOT: $(NDK_ROOT)) -$(info Using STRIP_TOOL: $(STRIP_TOOL)) - DEBUG_APK := tailscale-debug.apk RELEASE_AAB := tailscale-release.aab RELEASE_TV_AAB := tailscale-tv-release.aab @@ -64,6 +51,21 @@ ifeq ($(ANDROID_SDK_ROOT),) endif export ANDROID_HOME ?= $(ANDROID_SDK_ROOT) +# Auto-select an NDK from ANDROID_HOME (choose highest version available) +NDK_ROOT ?= $(shell ls -1d $(ANDROID_HOME)/ndk/* 2>/dev/null | sort -V | tail -n 1) + +HOST_OS := $(shell uname | tr A-Z a-z) +ifeq ($(HOST_OS),linux) + STRIP_TOOL := $(NDK_ROOT)/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-objcopy +else ifeq ($(HOST_OS),darwin) + STRIP_TOOL := $(NDK_ROOT)/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-objcopy +endif + +$(info Using ANDROID_HOME: $(ANDROID_HOME)) +$(info Using NDK_ROOT: $(NDK_ROOT)) +$(info Using STRIP_TOOL: $(STRIP_TOOL)) + + # Attempt to find Android Studio for Linux configuration, which does not have a # predetermined location. ANDROID_STUDIO_ROOT ?= $(shell find ~/android-studio /usr/local/android-studio /opt/android-studio /Applications/Android\ Studio.app $(PROGRAMFILES)/Android/Android\ Studio -type d -maxdepth 1 2>/dev/null | head -n 1) @@ -312,7 +314,7 @@ checkandroidsdk: ## Check that Android SDK is installed test: gradle-dependencies ## Run the Android tests (cd android && ./gradlew test) -.PHONY: emulator +.PHONY: emulator emulator: ## Start an android emulator instance @echo "Checking installed SDK packages..." @if ! $(ANDROID_HOME)/cmdline-tools/latest/bin/sdkmanager --list_installed | grep -q "$(AVD_IMAGE)"; then \ @@ -327,7 +329,7 @@ emulator: ## Start an android emulator instance @echo "Starting emulator..." @$(ANDROID_HOME)/emulator/emulator -avd "$(AVD)" -logcat-output /dev/stdout -netdelay none -netspeed full -.PHONY: install +.PHONY: install install: $(DEBUG_APK) ## Install the debug APK on a connected device adb install -r $< @@ -335,7 +337,7 @@ install: $(DEBUG_APK) ## Install the debug APK on a connected device run: install ## Run the debug APK on a connected device adb shell am start -n com.tailscale.ipn/com.tailscale.ipn.MainActivity -.PHONY: docker-build-image +.PHONY: docker-build-image docker-build-image: ## Builds the docker image for the android build environment if it does not exist @echo "Checking if docker image $(DOCKER_IMAGE) already exists..." @if ! docker images $(DOCKER_IMAGE) -q | grep -q . ; then \