Skip to content

Commit 72c4104

Browse files
committed
Makefile: add command to start emulator
This emulator command starts an emulator and keeps running in the foreground so as to avoid creating zombies. Updates #343 Co-authored-by: [email protected] Signed-off-by: James Tucker <[email protected]>
1 parent 001e795 commit 72c4104

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

Makefile

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ else
7272
export PATH := $(JAVA_HOME)/bin:$(PATH)
7373
endif
7474

75+
AVD_BASE_IMAGE := "system-images;android-33;google_apis;"
76+
export HOST_ARCH=$(shell uname -m)
77+
ifeq ($(HOST_ARCH),aarch64)
78+
AVD_IMAGE := "$(AVD_BASE_IMAGE)arm64-v8a"
79+
else ifeq ($(HOST_ARCH),arm64)
80+
AVD_IMAGE := "$(AVD_BASE_IMAGE)arm64-v8a"
81+
else
82+
AVD_IMAGE := "$(AVD_BASE_IMAGE)x86_64"
83+
endif
84+
AVD ?= tailscale-$(HOST_ARCH)
85+
export AVD_IMAGE
86+
export AVD
87+
7588
# TOOLCHAINDIR is set by fdoid CI and used by tool/* scripts.
7689
TOOLCHAINDIR ?=
7790
export TOOLCHAINDIR
@@ -160,6 +173,7 @@ env:
160173
@echo ANDROID_STUDIO_ROOT=$(ANDROID_STUDIO_ROOT)
161174
@echo JAVA_HOME=$(JAVA_HOME)
162175
@echo TOOLCHAINDIR=$(TOOLCHAINDIR)
176+
@echo AVD_IMAGE="$(AVD_IMAGE)"
163177

164178
# Ensure that JKS_PATH and JKS_PASSWORD are set before we attempt a build
165179
# that requires signing.
@@ -238,6 +252,21 @@ checkandroidsdk: ## Check that Android SDK is installed
238252
test: gradle-dependencies ## Run the Android tests
239253
(cd android && ./gradlew test)
240254

255+
.PHONY: emulator
256+
emulator: ## Start an android emulator instance
257+
@echo "Checking installed SDK packages..."
258+
@if ! $(ANDROID_HOME)/cmdline-tools/latest/bin/sdkmanager --list_installed | grep -q "$(AVD_IMAGE)"; then \
259+
echo "$(AVD_IMAGE) not found, installing..."; \
260+
$(ANDROID_HOME)/cmdline-tools/latest/bin/sdkmanager "$(AVD_IMAGE)"; \
261+
fi
262+
@echo "Checking if AVD exists..."
263+
@if ! $(ANDROID_HOME)/cmdline-tools/latest/bin/avdmanager list avd | grep -q "$(AVD)"; then \
264+
echo "AVD $(AVD) not found, creating..."; \
265+
$(ANDROID_HOME)/cmdline-tools/latest/bin/avdmanager create avd -n "$(AVD)" -k "$(AVD_IMAGE)"; \
266+
fi
267+
@echo "Starting emulator..."
268+
@$(ANDROID_HOME)/emulator/emulator -avd "$(AVD)" -logcat-output /dev/stdout -netdelay none -netspeed full
269+
241270
.PHONY: install
242271
install: $(DEBUG_APK) ## Install the debug APK on a connected device
243272
adb install -r $<
@@ -278,7 +307,7 @@ docker-remove-shell-image: ## Removes all docker shell image
278307
clean: ## Remove build artifacts. Does not purge docker build envs. Use dockerRemoveEnv for that.
279308
clean: ## Remove build artifacts. Does not purge docker build envs. Use dockerRemoveEnv for that.
280309
@echo "Cleaning up old build artifacts"
281-
-rm -rf android/build $(DEBUG_APK) $(RELEASE_AAB) $(RELEASE_TV_AAB) $(LIBTAILSCALE) android/libs *.apk *.aab
310+
-rm -rf android/build $(DEBUG_APK) $(RELEASE_AAB) $(RELEASE_TV_AAB) $(LIBTAILSCALE) android/libs *.apk *.aab
282311
@echo "Cleaning cached toolchain"
283312
-rm -rf $(HOME)/.cache/tailscale-go
284313
-pkill -f gradle

0 commit comments

Comments
 (0)