nandi/frqpublic Fork 0
8a491bab8ddb779dbb345ca249ac7169a099c36a
Commits
Clone
git clone https://git.rickub.com/nandi/frq.git
git clone ssh://git@rickub.com/nandi/frq.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

build-apk.sh · 118 lines · 4.2 KBBash Blame HistoryRaw
A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 20d ago1#!/usr/bin/env bash
2# Glue the two halves of the frq Android app into an APK.
3#
4# libvidya.so the C ABI on Rust/egui, cross-compiled by buck2, and the
5# NativeActivity's own library (it holds android-activity's
6# glue, so it owns the event loop)
7# libjoltapp.so vidya's android/jolt_main.c plus frq's Jolt boot image,
8# dlopened by the above
9#
10# Neither half is built here beyond that last link: the UI library comes from
11# vidya's `just ffi-android` and the boot image from build-jolt-boot.sh. Both
12# native pieces are vidya's — only the boot image is frq's.
13set -euo pipefail
14
15ROOT="$(cd "$(dirname "$0")/.." && pwd)"
16VIDYA="${VIDYA:-$(cd "$ROOT/../vidya" && pwd)}"
17ANDROID_HOME="${ANDROID_HOME:-$HOME/.local/share/android-sdk}"
18ANDROID_NDK_HOME="${ANDROID_NDK_HOME:-$HOME/.local/share/android-ndk-r29}"
19CHEZ_ANDROID="${CHEZ_ANDROID:-$HOME/.cache/vidya-chez-android}"
20BUILD="$ROOT/android/build"
21JOLT_BUILD="$BUILD/jolt"
22STAGE="$BUILD/stage"
23TOOLS="$ANDROID_HOME/build-tools/36.0.0"
24ADB="${ADB:-$ANDROID_HOME/platform-tools/adb}"
25NDK_BIN="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin"
26PACKAGE="uk.nandi.frq"
27ACTIVITY="$PACKAGE/android.app.NativeActivity"
28API=28
29
30for path in \
31 "$NDK_BIN/aarch64-linux-android$API-clang" \
32 "$ANDROID_HOME/platforms/android-36/android.jar" \
33 "$TOOLS/aapt2" "$TOOLS/zipalign" "$TOOLS/apksigner"; do
34 [[ -e "$path" ]] || { echo "missing Android tool: $path" >&2; exit 1; }
35done
36
37# --- the UI half ------------------------------------------------------------
38( cd "$VIDYA" && just ffi-android >&2 )
39VIDYA_SO="$VIDYA/build/android/arm64-v8a/libvidya.so"
40[[ -f "$VIDYA_SO" ]] || { echo "missing $VIDYA_SO" >&2; exit 1; }
41
42# --- the Jolt half ----------------------------------------------------------
43"$ROOT/android/build-jolt-boot.sh" "$JOLT_BUILD"
44(
45 cd "$JOLT_BUILD"
46 # The boot image travels as a blob in the object file's data section; the
47 # _binary_jolt_boot_{start,end} symbols jolt_main.c reads come from this.
48 "$NDK_BIN/llvm-objcopy" \
49 --input-target=binary \
50 --output-target=elf64-littleaarch64 \
51 --binary-architecture=aarch64 \
52 jolt.boot jolt_boot.o
53)
54
55rm -rf "$STAGE"
56mkdir -p "$STAGE/lib/arm64-v8a"
57cp "$VIDYA_SO" "$STAGE/lib/arm64-v8a/libvidya.so"
58
59"$NDK_BIN/aarch64-linux-android$API-clang" \
60 -shared -fPIC -O2 \
61 -o "$STAGE/lib/arm64-v8a/libjoltapp.so" \
62 "$VIDYA/android/jolt_main.c" \
63 "$JOLT_BUILD/jolt_boot.o" \
64 -I"$JOLT_BUILD" \
65 -I"$VIDYA/raylib/include" \
66 -I"$VIDYA/ffi/include" \
67 -L"$STAGE/lib/arm64-v8a" \
68 "$CHEZ_ANDROID/tarm64le/boot/tarm64le/libkernel.a" \
69 "$CHEZ_ANDROID/lz4/lib/liblz4.a" \
70 -lvidya -landroid -llog -lz -ldl -lm \
71 -Wl,--no-undefined
72
73# --- the APK ----------------------------------------------------------------
74UNALIGNED="$BUILD/frq-unaligned.apk"
75ALIGNED="$BUILD/frq-aligned.apk"
76APK="$BUILD/frq.apk"
77rm -f "$UNALIGNED" "$ALIGNED" "$APK"
78"$TOOLS/aapt2" link \
79 -o "$UNALIGNED" \
80 -I "$ANDROID_HOME/platforms/android-36/android.jar" \
81 --manifest "$ROOT/android/AndroidManifest.xml" \
82 --min-sdk-version $API \
83 --target-sdk-version 36 \
84 --version-code 1 \
85 --version-name 0.1.0
86# Stored, not deflated: the loader maps these straight out of the APK.
87(cd "$STAGE" && zip -q -0 "$UNALIGNED" \
88 lib/arm64-v8a/libvidya.so lib/arm64-v8a/libjoltapp.so)
89"$TOOLS/zipalign" -f -p 4 "$UNALIGNED" "$ALIGNED"
90
91KEYSTORE="$HOME/.android/debug.keystore"
92if [[ ! -f "$KEYSTORE" ]]; then
93 mkdir -p "$(dirname "$KEYSTORE")"
94 keytool -genkeypair -v \
95 -keystore "$KEYSTORE" -storepass android -keypass android \
96 -alias androiddebugkey -keyalg RSA -keysize 2048 -validity 10000 \
97 -dname "CN=Android Debug,O=Android,C=US"
98fi
99"$TOOLS/apksigner" sign \
100 --ks "$KEYSTORE" --ks-key-alias androiddebugkey \
101 --ks-pass pass:android --key-pass pass:android \
102 --out "$APK" "$ALIGNED"
103"$TOOLS/apksigner" verify "$APK" >/dev/null
104
105case "${1:-build}" in
106 build) printf '%s\n' "$APK" ;;
107 install) "$ADB" install -r "$APK" ;;
108 run)
109 "$ADB" install -r "$APK"
110 "$ADB" shell am force-stop "$PACKAGE"
111 "$ADB" shell am start -n "$ACTIVITY"
112 ;;
113 log) "$ADB" logcat -s VidyaJolt Vidya ;;
114 *)
115 echo "usage: $0 [build|install|run|log]" >&2
116 exit 2
117 ;;
118esac