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 8c3c524
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 28 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:


build-apk:
name: Build APK (${{ matrix.os }}, java-${{ matrix.java_version }})
name: Build APK & AAB (${{ matrix.os }}, java-${{ matrix.java_version }})
runs-on: ${{ matrix.os }}
needs: [build-rust]
env:
Expand All @@ -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 @@ -197,19 +197,26 @@ jobs:
cat android.jks.age | age -d -i android.jks.key -o android.jks
rm android.jks.key
- name: Assemble APK
- name: Assemble APK and AAB
env:
JKS_STOREPASS: ${{ secrets.KEY_ANDROID_JKS_STOREPASS }}
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
40 changes: 28 additions & 12 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,32 +60,43 @@ 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)

# 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_TYPE)/mobile-$(RELEASE_TYPE).aab
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"
cp $< $@
else
./scripts/sign_apk.sh $< $@
endif

# Signed release APK
dist/aw-android.apk: $(APKDIR)/release/mobile-release-unsigned.apk
@# TODO: Name the APK based on the version number or commit hash.
dist/aw-android.apk: $(APKDIR)/$(RELEASE_TYPE)/mobile-$(RELEASE_TYPE)-unsigned.apk
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"
@echo "No key secrets set, not signing"
cp $< $@
else
./scripts/sign_apk.sh $< $@
endif

# for mobile-debug.apk and mobile-debug-androidTest.apk
dist/debug/%: $(APKDIR)/debug/%
dist/$(RELEASE_TYPE)/%: $(APKDIR)/$(RELEASE_TYPE)/%
mkdir -p dist
cp $< $@

Expand All @@ -103,7 +119,7 @@ TARGET_x64 := $(TARGET)/x86_64-linux-android
TARGET_x86 := $(TARGET)/i686-linux-android

# Build webui specifically for Android (disabled update check, different default views, etc)
export ON_ANDROID := -- --android
export ON_ANDROID := -- --android

aw-server-rust: $(JNILIBS)

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 8c3c524

Please sign in to comment.