Files
EasyLPAC/scripts/build-android.sh
creamlike1024 76d210ce48 build(android): add the Android build script and version codes
scripts/build-android.sh builds the arm64 APK and AAB with a JDK 17,
and build-libeuicc.sh builds for Android with the NDK.

mygo took a snapshot such as 0.9.2.r12.g... to be versionCode 900,
below 0.9.2's 902, which Android refuses as a downgrade.
android-version-code.sh gives a code that grows with the versions of
version.sh, and with-version.sh puts it in mygo.json for the build.
2026-11-22 21:04:02 +08:00

44 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Builds the Android APK and AAB (arm64): libeuicc with the NDK, then the
# app with MyGo and Gradle. Extra arguments go to `mygo build`.
#
# ./scripts/build-android.sh # build/android/
#
# Needs the Android SDK (Platform 36, Build-Tools 35.0.0, an NDK) and a
# JDK 17, which MyGo's Gradle build asks for: Android Studio's own JDK is
# too new for its Gradle (8.14, which runs on Java 24 at most). The JDK is
# JAVA_HOME if that is a 17, or else the system's or Homebrew's.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
is_jdk17() {
[ -x "$1/bin/java" ] || return 1
local out
out="$("$1/bin/java" -version 2>&1)" || return 1
[[ "$out" == *'version "17'* ]]
}
JDK=
for h in "${JAVA_HOME:-}" \
/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home \
/usr/local/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home \
/Library/Java/JavaVirtualMachines/*17*/Contents/Home \
/usr/lib/jvm/*17*; do
if [ -n "$h" ] && is_jdk17 "$h"; then
JDK="$h"
break
fi
done
if [ -z "$JDK" ]; then
echo "build-android.sh: no JDK 17: install one, or set JAVA_HOME to it" >&2
exit 1
fi
export JAVA_HOME="$JDK"
if [ ! -f third_party/libeuicc/android-arm64/libeuicc.a ]; then
./scripts/build-libeuicc.sh android/arm64
fi
EASYLPAC_ANDROID=1 \
./scripts/with-version.sh go run github.com/egoist/mygo/cmd/mygo@v0.10.0 build -platform android/arm64 "$@"