Skip to content

Commit

Permalink
build: added bundle (.aab) building
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Oct 8, 2023
1 parent e737d31 commit 1365b79
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 22 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: 'recursive'

- uses: ActivityWatch/check-version-format-action@v2
id: version
with:
prefix: 'v'

- name: Echo version
run: |
echo "${{ steps.version.outputs.full }} (stable: ${{ steps.version.outputs.is_stable }})"
Expand Down Expand Up @@ -203,13 +203,20 @@ jobs:
JKS_KEYPASS: ${{ secrets.KEY_ANDROID_JKS_KEYPASS }}
run: |
make dist/aw-android.apk
make dist/aw-android.aab
- name: Upload release APK
- name: Upload APK
uses: actions/upload-artifact@v3
with:
name: aw-android
path: dist/aw-android*.apk

- name: Upload AAB
uses: actions/upload-artifact@v3
with:
name: aw-android
path: dist/aw-android*.aab

test-e2e:
name: Test E2E ${{ matrix.android_avd }} #-${{ matrix.os }}-eAPI-${{ matrix.android_emu_version }}-java-${{ matrix.java_version }}-node-${{ matrix.node_version }}
needs: [build-rust]
Expand Down
34 changes: 26 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ SHELL := /bin/bash
# - https://developer.android.com/ndk/guides/android_mk

RELEASE_TYPE = $(shell test -n "$$RELEASE" && $$RELEASE && echo 'release' || echo 'debug')
RELEASE_TYPE_CAPS = $(shell test -n "$$RELEASE" && $$RELEASE && echo 'Release' || echo 'Debug')
HAS_SECRETS = $(shell test -n "$$JKS_KEYPASS" && echo 'true' || echo 'false')

APKDIR = mobile/build/outputs/apk
AABDIR = mobile/build/outputs/bundle

WEBUI_SRCDIR := aw-server-rust/aw-webui
WEBUI_DISTDIR := $(WEBUI_SRCDIR)/dist
Expand All @@ -16,6 +18,9 @@ WEBUI_DISTDIR := $(WEBUI_SRCDIR)/dist
all: aw-server-rust
build: all

# builds an app bundle, puts it in dist
build-bundle: dist/aw-android.aab

# builds a complete, signed apk, puts it in dist
build-apk: dist/aw-android.apk

Expand Down Expand Up @@ -55,19 +60,32 @@ install-apk-debug: $(APKDIR)/debug/mobile-debug.apk
adb install $(APKDIR)/debug/mobile-debug-androidTest.apk

# APK targets
$(APKDIR)/release/mobile-release-unsigned.apk:
TERM=xterm ./gradlew assembleRelease
tree $(APKDIR)

$(APKDIR)/debug/mobile-debug.apk:
TERM=xterm ./gradlew assembleDebug
$(APKDIR)/$(RELEASE_TYPE)/mobile-$(RELEASE_TYPE)%.apk:
TERM=xterm ./gradlew assemble$(RELEASE_TYPE_CAPS)
tree $(APKDIR)

$(APKDIR)/androidTest/debug/mobile-debug-androidTest.apk:
$(APKDIR)/androidTest/$(RELEASE_TYPE)/mobile-$(RELEASE_TYPE)-androidTest.apk:
TERM=xterm ./gradlew assembleAndroidTest
tree $(APKDIR)

# Signed release APK
# App bundle targets
$(AABDIR)/$(RELEASE_TYPE)/mobile-$(RELEASE_TYPE).aab:
TERM=xterm ./gradlew bundle$(RELEASE_TYPE_CAPS)
tree $(AABDIR)

# Signed release bundle
dist/aw-android.aab: $(AABDIR)/release/mobile-release.aab
@# TODO: Name the APK based on the version number or commit hash.
mkdir -p dist
@# Only sign if we have key secrets set ($JKS_KEYPASS and $JKS_STOREPASS)
ifneq ($(HAS_SECRETS), true)
@echo "No key secrets set, not signing APK"
cp $< $@
else
./scripts/sign_apk.sh $< $@
endif

# Signed release APK/Bundle
dist/aw-android.apk: $(APKDIR)/release/mobile-release-unsigned.apk
@# TODO: Name the APK based on the version number or commit hash.
mkdir -p dist
Expand Down
36 changes: 25 additions & 11 deletions scripts/sign_apk.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

# Signs APKs or AABs using the android.jks keystore

set -e

input=$1
Expand All @@ -22,19 +24,31 @@ if [ -z $JKS_KEYPASS ]; then
fi

# Zipalign
zipalign=$(find $ANDROID_HOME/build-tools -name "zipalign" -print | head -n 1)
$zipalign -v -p 4 $input $input.new
mv $input.new $input
# Not needed for AABs
if [[ $input == *.apk ]]; then
zipalign=$(find $ANDROID_HOME/build-tools -name "zipalign" -print | head -n 1)
$zipalign -v -p 4 $input $input.new
mv $input.new $input
fi

# Sign
# Using apksigner instead of jarsigner since API 30+: https://stackoverflow.com/a/69473649
apksigner=$(find $ANDROID_HOME/build-tools -name "apksigner" -print | head -n 1)
$apksigner sign --ks android.jks --ks-key-alias activitywatch \
--ks-pass env:JKS_STOREPASS --key-pass env:JKS_KEYPASS \
$input

# Verify
$apksigner verify $input
# Using apksigner for APKs instead of jarsigner since API 30+: https://stackoverflow.com/a/69473649
# Using jarsigner for AABs since apksigner doesn't support them
if [[ $input == *.apk ]]; then
apksigner=$(find $ANDROID_HOME/build-tools -name "apksigner" -print | head -n 1)
$apksigner sign --ks android.jks --ks-key-alias activitywatch \
--ks-pass env:JKS_STOREPASS --key-pass env:JKS_KEYPASS \
$input

# Verify
$apksigner verify $input
fi
if [[ $input == *.aab ]]; then
jarsigner -verbose \
-keystore android.jks activitywatch \
-storepass $JKS_STOREPASS -keypass $JKS_KEYPASS \
$input activitywatch
fi

# Move to output destination
mv $input $output

0 comments on commit 1365b79

Please sign in to comment.