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