The Android host no longer needs the scaffold to pass WebP, AVIF and libaom source directories. The generated link follows the application's imports: Android's own image decoder serves the Image widget by default, `kryon/android_avif` adds a dav1d decoder (libaom only when the app imports AVIF encoding or the libaom engine) and `kryon/android_webp` adds libwebp's first-frame decoder. Packages declare their native recipes and source aliases under [tool.android.native]. Android text and emoji come from the system unless `bundled_fonts = true`. `frame_mode = "events"` sleeps between updates and paces active frames with the display; `kryon/android_frames` exposes AndroidRequestFrame for worker and timed wakeups. Adaptive pacing remains the default, and a debug frame watch reports stalled window-loop work. The droid scaffold upgrades known stock Gradle, CMake and Activity files and preserves customized ones, and needs Python 3.11. Pin the avif, webp and audio packages and Ziran c041afb6, relocked from the pinned packages.
117 lines
4.2 KiB
Bash
117 lines
4.2 KiB
Bash
#!/bin/sh
|
|
# Build, run or check the Android profile of a Kryon application.
|
|
#
|
|
# The kryon project tool sets KRYON_DIR, ZIRAN_DIR, KRYON_PROJECT_ROOT and
|
|
# KRYON_ANDROID_* from ziran.toml and runs this from the project root:
|
|
# sh scripts/android-build.sh build|run|check
|
|
set -eu
|
|
|
|
verb="${1:-build}"
|
|
root="${KRYON_PROJECT_ROOT:-$PWD}"
|
|
kryon_dir="${KRYON_DIR:?kryon: KRYON_DIR must name the Kryon checkout}"
|
|
ziran_dir="${ZIRAN_DIR:?kryon: ZIRAN_DIR must name the pinned Ziran toolchain}"
|
|
package="${KRYON_ANDROID_PACKAGE:?kryon: set [tool.kryon.android] package in ziran.toml}"
|
|
activity="${KRYON_ANDROID_ACTIVITY:-MainActivity}"
|
|
abis="${KRYON_ANDROID_ABIS:-arm64-v8a}"
|
|
min_sdk="${KRYON_ANDROID_MIN_SDK:-21}"
|
|
codegen="${KRYON_PROJECT_CODEGEN:-c99}"
|
|
|
|
cd "$root"
|
|
if [ ! -f ziran.toml ]; then
|
|
echo "kryon: no ziran.toml in $root; run this through kryon build --profile android" >&2
|
|
exit 2
|
|
fi
|
|
|
|
ziran_bin="$ziran_dir/build/bin/ziran"
|
|
zi2c_bin="$ziran_dir/build/bin/zi2c"
|
|
if [ ! -x "$ziran_bin" ] || [ ! -x "$zi2c_bin" ]; then
|
|
echo "kryon: building the pinned Ziran toolchain" >&2
|
|
make -j4 -C "$ziran_dir" build/bin/ziran build/bin/zi2c build/bin/zi2zir
|
|
fi
|
|
|
|
if [ "$codegen" = "zx" ]; then
|
|
python3 "$kryon_dir/scripts/android_scaffold.py" \
|
|
--root "$root" --name "${KRYON_PROJECT_NAME:-app}" \
|
|
--package "$package" --activity "$activity" --kryon "$kryon_dir"
|
|
make --silent --no-print-directory -f "$kryon_dir/mk/ziran-project.mk" build \
|
|
"PROJECT_NAME=$KRYON_PROJECT_NAME" "PROJECT_ENTRY=$KRYON_PROJECT_ENTRY" \
|
|
PROJECT_BACKEND=desktop PROJECT_CODEGEN=zx \
|
|
"PROJECT_PROFILE=$KRYON_PROJECT_PROFILE" \
|
|
"PROJECT_ASSETS=${KRYON_PROJECT_ASSETS:-}" \
|
|
"KRYON_DIR=$kryon_dir" "ZIRAN_DIR=$ziran_dir"
|
|
mkdir -p "$root/build/android/zx-assets"
|
|
rm -f "$root/build/android/zx-assets/kryon-font.ttf"
|
|
cp "$root/build/$KRYON_PROJECT_NAME-$KRYON_PROJECT_PROFILE.zx" \
|
|
"$root/build/android/zx-assets/app.zx"
|
|
elif [ "$codegen" != "c99" ]; then
|
|
echo "kryon: unsupported Android codegen $codegen" >&2
|
|
exit 2
|
|
fi
|
|
|
|
if [ "$verb" = "check" ]; then
|
|
# The generator parses, checks and lowers the whole Zi graph; the arch
|
|
# define matches a phone build without needing the NDK.
|
|
rm -rf "$root/build/android/check"
|
|
python3 "$kryon_dir/scripts/generate_android_sources.py" \
|
|
--ziran "$ziran_bin" --zi2c "$ziran_dir/build/bin/zi2c" \
|
|
--root "$root" --kryon "$kryon_dir" \
|
|
--ir "$root/build/android/check/ir" \
|
|
--output "$root/build/android/check/generated" \
|
|
--manifest "$root/build/android/check/generated-sources.cmake" \
|
|
--codegen "$codegen" \
|
|
--define ANDROID_BUILD --define __aarch64__
|
|
echo "kryon: android profile checked"
|
|
exit 0
|
|
fi
|
|
|
|
python3 "$kryon_dir/scripts/android_scaffold.py" \
|
|
--root "$root" --name "${KRYON_PROJECT_NAME:-app}" \
|
|
--package "$package" --activity "$activity" --kryon "$kryon_dir"
|
|
|
|
if [ -z "${ANDROID_HOME:-}" ] && [ -d "$HOME/Android/Sdk" ]; then
|
|
ANDROID_HOME="$HOME/Android/Sdk"
|
|
export ANDROID_HOME
|
|
fi
|
|
if ! command -v java >/dev/null 2>&1; then
|
|
echo "kryon: Gradle needs a JDK; install one (for example a headless openjdk)" >&2
|
|
exit 2
|
|
fi
|
|
|
|
run_gradle() {
|
|
if [ -f ./droid/gradlew ]; then
|
|
sh ./droid/gradlew "$@"
|
|
else
|
|
gradle "$@"
|
|
fi
|
|
}
|
|
|
|
run_gradle -p droid assembleDebug \
|
|
-Pkryon.dir="$kryon_dir" -Pziran.dir="$ziran_dir" \
|
|
-Papp.minSdk="$min_sdk" -Papp.abis="$abis" -Papp.codegen="$codegen"
|
|
|
|
apk="droid/app/build/outputs/apk/debug/app-debug.apk"
|
|
if [ ! -f "$apk" ]; then
|
|
echo "kryon: gradle did not produce $apk" >&2
|
|
exit 2
|
|
fi
|
|
|
|
if [ "$verb" = "run" ]; then
|
|
adb="${ANDROID_HOME:-$HOME/Android/Sdk}/platform-tools/adb"
|
|
if ! command -v "$adb" >/dev/null 2>&1; then
|
|
adb="$(command -v adb || true)"
|
|
fi
|
|
if [ -z "$adb" ]; then
|
|
echo "kryon: adb not found; install the APK manually from $apk" >&2
|
|
exit 2
|
|
fi
|
|
# With several devices attached, ANDROID_SERIAL selects the target.
|
|
serial="${ANDROID_SERIAL:-}"
|
|
if [ -n "$serial" ]; then
|
|
set -- -s "$serial"
|
|
else
|
|
set --
|
|
fi
|
|
"$adb" "$@" install -r "$apk"
|
|
"$adb" "$@" shell am start -n "$package/.$activity"
|
|
fi
|