From 2f59feef20121f51c54fd6a9f517a70ab65c041f Mon Sep 17 00:00:00 2001 From: Jonathan Nobels Date: Mon, 15 Jul 2024 15:02:52 -0400 Subject: [PATCH] android/makefile: add tv-specific build variant (#445) android/makefile: add tv-specific build updates tailscale/corp#21644 This will build a second tailscale-release-tv.aab with the leanback flag set suitable for submission for android-tv. Signed-off-by: Jonathan Nobels --- .gitignore | 8 ++------ Makefile | 26 ++++++++++++++++++++++---- android/build.gradle | 16 ++++++++++++++++ android/src/main/AndroidManifest.xml | 2 +- docker/DockerFile.amd64-build | 4 ++++ 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 83d914f..aab9616 100644 --- a/.gitignore +++ b/.gitignore @@ -19,12 +19,8 @@ android/local.properties .idea # Output files from the Makefile: -tailscale-debug.apk -tailscale-release.aab -tailscale-fdroid.apk -tailscale-new-fdroid.apk -tailscale-new-debug.apk -tailscale-test.apk +*.apk +*.aab # Signing key tailscale.jks diff --git a/Makefile b/Makefile index 2c6b1c8..cfe72fc 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,11 @@ # The docker image to use for the build environment. Changing this # will force a rebuild of the docker image. If there is an existing image # with this name, it will be used. -DOCKER_IMAGE=tailscale-android-build-amd64-1 +DOCKER_IMAGE=tailscale-android-build-amd64-2 DEBUG_APK=tailscale-debug.apk RELEASE_AAB=tailscale-release.aab +RELEASE_TV_AAB=tailscale-tv-release.aab LIBTAILSCALE=android/libs/libtailscale.aar TAILSCALE_VERSION=$(shell ./version/tailscale-version.sh 200) OUR_VERSION=$(shell git describe --dirty --exclude "*" --always --abbrev=200) @@ -88,10 +89,16 @@ apk: $(DEBUG_APK) ## Build the debug APK .PHONY: tailscale-debug tailscale-debug: $(DEBUG_APK) ## Build the debug APK +# Builds the release AAB and signs it (phone/tablet/chromeOS variant) .PHONY: release release: jarsign-env $(RELEASE_AAB) ## Build the release AAB @jarsigner -sigalg SHA256withRSA -digestalg SHA-256 -keystore $(JKS_PATH) -storepass $(JKS_PASSWORD) $(RELEASE_AAB) tailscale +# Builds the release AAB and signs it (androidTV variant) +.PHONY: release-tv +release-tv: jarsign-env $(RELEASE_TV_AAB) ## Build the release AAB + @jarsigner -sigalg SHA256withRSA -digestalg SHA-256 -keystore $(JKS_PATH) -storepass $(JKS_PASSWORD) $(RELEASE_TV_AAB) tailscale + # gradle-dependencies groups together the android sources and libtailscale needed to assemble tests/debug/release builds. .PHONY: gradle-dependencies gradle-dependencies: $(shell find android -type f -not -path "android/build/*" -not -path '*/.*') $(LIBTAILSCALE) @@ -104,6 +111,10 @@ $(RELEASE_AAB): gradle-dependencies (cd android && ./gradlew test bundleRelease) install -C ./android/build/outputs/bundle/release/android-release.aab $@ +$(RELEASE_TV_AAB): gradle-dependencies + (cd android && ./gradlew test bundleRelease_tv) + install -C ./android/build/outputs/bundle/release_tv/android-release_tv.aab $@ + tailscale-test.apk: gradle-dependencies (cd android && ./gradlew assembleApplicationTestAndroidTest) install -C ./android/build/outputs/apk/androidTest/applicationTest/android-applicationTest-androidTest.apk $@ @@ -166,9 +177,16 @@ androidpath: @echo "export ANDROID_SDK_ROOT=$(ANDROID_SDK_ROOT)" @echo 'export PATH=$(ANDROID_HOME)/cmdline-tools/latest/bin:$(ANDROID_HOME)/platform-tools:$$PATH' -.PHONY: tag_release -tag_release: ## Tag a release +.PHONY: bump_version_code +bump_version_code: ## Bump the version code in the android build.gradle + @echo "Current Version Code:" + @grep "versionCode" android/build.gradle sed -i'.bak' 's/versionCode $(VERSIONCODE)/versionCode $(VERSIONCODE_PLUSONE)/' android/build.gradle && rm android/build.gradle.bak + @echo "New Version Code:" + @grep "versionCode" android/build.gradle + +.PHONY: tag_release +tag_release: bump_version_code ## Increment the playstore version code by 1 sed -i'.bak' 's/versionName .*/versionName "$(VERSION_LONG)"/' android/build.gradle && rm android/build.gradle.bak git commit -sm "android: bump version code" android/build.gradle git tag -a "$(VERSION_LONG)" @@ -249,7 +267,7 @@ docker-remove-shell-image: ## Removes all docker shell image .PHONY: clean clean: ## Remove build artifacts. Does not purge docker build envs. Use dockerRemoveEnv for that. - -rm -rf android/build $(DEBUG_APK) $(RELEASE_AAB) $(LIBTAILSCALE) android/libs *.apk *.aab + -rm -rf android/build $(DEBUG_APK) $(RELEASE_AAB) $(RELEASE_TV_AAB) $(LIBTAILSCALE) android/libs *.apk *.aab -pkill -f gradle .PHONY: help diff --git a/android/build.gradle b/android/build.gradle index 84b8862..3ede1ee 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -65,11 +65,27 @@ android { buildTypes { applicationTest { initWith debug + manifestPlaceholders.leanbackRequired = false buildConfigField "String", "GITHUB_USERNAME", "\"" + getLocalProperty("githubUsername")+"\"" buildConfigField "String", "GITHUB_PASSWORD", "\"" + getLocalProperty("githubPassword")+"\"" buildConfigField "String", "GITHUB_2FA_SECRET", "\"" + getLocalProperty("github2FASecret")+"\"" } + debug { + manifestPlaceholders.leanbackRequired = false + } release { + manifestPlaceholders.leanbackRequired = false + minifyEnabled true + + shrinkResources true + + proguardFiles getDefaultProguardFile( + 'proguard-android-optimize.txt'), + 'proguard-rules.pro' + } + release_tv { + manifestPlaceholders.leanbackRequired = true + minifyEnabled true shrinkResources true diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 56e75a2..d7f224d 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -24,7 +24,7 @@ + android:required="${leanbackRequired}" /> diff --git a/docker/DockerFile.amd64-build b/docker/DockerFile.amd64-build index e05bfdf..7abe6e1 100644 --- a/docker/DockerFile.amd64-build +++ b/docker/DockerFile.amd64-build @@ -44,4 +44,8 @@ RUN ./android/gradlew # Build the android app CMD make clean CMD make release +# Build the android tv app. We need to bump the version code by 1 +# so the AAB is unique. +CMD make bump_version_code +CMD make release-tv