nandi/frqpublic Fork 0
7b6e915f42dce773f5537ebf6ae2d8e2cc3f4e81
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 · 141 lines · 5.4 KBBash Blame HistoryRaw
A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 21d 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
Sign in and choose a picture on the phone 7b6e915 nandi 20d ago9# classes.dex one Java class, and only because a picture chooser answers
10# through onActivityResult and a NativeActivity has nowhere to
11# deliver that
A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 21d ago12#
13# Neither half is built here beyond that last link: the UI library comes from
14# vidya's `just ffi-android` and the boot image from build-jolt-boot.sh. Both
15# native pieces are vidya's — only the boot image is frq's.
16set -euo pipefail
17
18ROOT="$(cd "$(dirname "$0")/.." && pwd)"
19VIDYA="${VIDYA:-$(cd "$ROOT/../vidya" && pwd)}"
20ANDROID_HOME="${ANDROID_HOME:-$HOME/.local/share/android-sdk}"
21ANDROID_NDK_HOME="${ANDROID_NDK_HOME:-$HOME/.local/share/android-ndk-r29}"
22CHEZ_ANDROID="${CHEZ_ANDROID:-$HOME/.cache/vidya-chez-android}"
23BUILD="$ROOT/android/build"
24JOLT_BUILD="$BUILD/jolt"
25STAGE="$BUILD/stage"
26TOOLS="$ANDROID_HOME/build-tools/36.0.0"
27ADB="${ADB:-$ANDROID_HOME/platform-tools/adb}"
28NDK_BIN="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin"
29PACKAGE="uk.nandi.frq"
Sign in and choose a picture on the phone 7b6e915 nandi 20d ago30ACTIVITY="$PACKAGE/.FrqActivity"
A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 21d ago31API=28
32
33for path in \
34 "$NDK_BIN/aarch64-linux-android$API-clang" \
35 "$ANDROID_HOME/platforms/android-36/android.jar" \
Sign in and choose a picture on the phone 7b6e915 nandi 20d ago36 "$TOOLS/aapt2" "$TOOLS/zipalign" "$TOOLS/apksigner" "$TOOLS/d8"; do
A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 21d ago37 [[ -e "$path" ]] || { echo "missing Android tool: $path" >&2; exit 1; }
38done
39
40# --- the UI half ------------------------------------------------------------
41( cd "$VIDYA" && just ffi-android >&2 )
42VIDYA_SO="$VIDYA/build/android/arm64-v8a/libvidya.so"
43[[ -f "$VIDYA_SO" ]] || { echo "missing $VIDYA_SO" >&2; exit 1; }
44
45# --- the Jolt half ----------------------------------------------------------
46"$ROOT/android/build-jolt-boot.sh" "$JOLT_BUILD"
47(
48 cd "$JOLT_BUILD"
49 # The boot image travels as a blob in the object file's data section; the
50 # _binary_jolt_boot_{start,end} symbols jolt_main.c reads come from this.
51 "$NDK_BIN/llvm-objcopy" \
52 --input-target=binary \
53 --output-target=elf64-littleaarch64 \
54 --binary-architecture=aarch64 \
55 jolt.boot jolt_boot.o
56)
57
Sign in and choose a picture on the phone 7b6e915 nandi 20d ago58# --- the Java half ----------------------------------------------------------
59# One class: the photo chooser's result has to land somewhere, and native code
60# is not somewhere. d8 turns it into the classes.dex the runtime loads.
61JAVA_BUILD="$BUILD/java"
62rm -rf "$JAVA_BUILD"
63mkdir -p "$JAVA_BUILD/classes"
64# android.jar on the class path is where every android.* type comes from; the
65# JDK's own java.* is what is left, and this class uses nothing of it that
66# Android does not have. (`-bootclasspath` would be the stricter way to say
67# that, and javac refuses it for a release this recent.)
68javac --release 17 \
69 --class-path "$ANDROID_HOME/platforms/android-36/android.jar" \
70 -d "$JAVA_BUILD/classes" \
71 "$ROOT/android/java/uk/nandi/frq/FrqActivity.java"
72"$TOOLS/d8" --min-api $API --output "$JAVA_BUILD" \
73 $(find "$JAVA_BUILD/classes" -name '*.class')
74
A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 21d ago75rm -rf "$STAGE"
76mkdir -p "$STAGE/lib/arm64-v8a"
Sign in and choose a picture on the phone 7b6e915 nandi 20d ago77cp "$JAVA_BUILD/classes.dex" "$STAGE/classes.dex"
A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 21d ago78cp "$VIDYA_SO" "$STAGE/lib/arm64-v8a/libvidya.so"
79
80"$NDK_BIN/aarch64-linux-android$API-clang" \
81 -shared -fPIC -O2 \
82 -o "$STAGE/lib/arm64-v8a/libjoltapp.so" \
83 "$VIDYA/android/jolt_main.c" \
84 "$JOLT_BUILD/jolt_boot.o" \
85 -I"$JOLT_BUILD" \
86 -I"$VIDYA/raylib/include" \
87 -I"$VIDYA/ffi/include" \
88 -L"$STAGE/lib/arm64-v8a" \
89 "$CHEZ_ANDROID/tarm64le/boot/tarm64le/libkernel.a" \
90 "$CHEZ_ANDROID/lz4/lib/liblz4.a" \
91 -lvidya -landroid -llog -lz -ldl -lm \
92 -Wl,--no-undefined
93
94# --- the APK ----------------------------------------------------------------
95UNALIGNED="$BUILD/frq-unaligned.apk"
96ALIGNED="$BUILD/frq-aligned.apk"
97APK="$BUILD/frq.apk"
98rm -f "$UNALIGNED" "$ALIGNED" "$APK"
99"$TOOLS/aapt2" link \
100 -o "$UNALIGNED" \
101 -I "$ANDROID_HOME/platforms/android-36/android.jar" \
102 --manifest "$ROOT/android/AndroidManifest.xml" \
103 --min-sdk-version $API \
104 --target-sdk-version 36 \
105 --version-code 1 \
106 --version-name 0.1.0
107# Stored, not deflated: the loader maps these straight out of the APK.
108(cd "$STAGE" && zip -q -0 "$UNALIGNED" \
109 lib/arm64-v8a/libvidya.so lib/arm64-v8a/libjoltapp.so)
Sign in and choose a picture on the phone 7b6e915 nandi 20d ago110# The dex is read by the runtime rather than mapped, so it may as well deflate.
111(cd "$STAGE" && zip -q "$UNALIGNED" classes.dex)
A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 21d ago112"$TOOLS/zipalign" -f -p 4 "$UNALIGNED" "$ALIGNED"
113
114KEYSTORE="$HOME/.android/debug.keystore"
115if [[ ! -f "$KEYSTORE" ]]; then
116 mkdir -p "$(dirname "$KEYSTORE")"
117 keytool -genkeypair -v \
118 -keystore "$KEYSTORE" -storepass android -keypass android \
119 -alias androiddebugkey -keyalg RSA -keysize 2048 -validity 10000 \
120 -dname "CN=Android Debug,O=Android,C=US"
121fi
122"$TOOLS/apksigner" sign \
123 --ks "$KEYSTORE" --ks-key-alias androiddebugkey \
124 --ks-pass pass:android --key-pass pass:android \
125 --out "$APK" "$ALIGNED"
126"$TOOLS/apksigner" verify "$APK" >/dev/null
127
128case "${1:-build}" in
129 build) printf '%s\n' "$APK" ;;
130 install) "$ADB" install -r "$APK" ;;
131 run)
132 "$ADB" install -r "$APK"
133 "$ADB" shell am force-stop "$PACKAGE"
134 "$ADB" shell am start -n "$ACTIVITY"
135 ;;
136 log) "$ADB" logcat -s VidyaJolt Vidya ;;
137 *)
138 echo "usage: $0 [build|install|run|log]" >&2
139 exit 2
140 ;;
141esac