Files
Ontime/build_all.sh
2026-04-01 11:55:47 +07:00

168 lines
4.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Prefer Java 17 for old Gradle builds to avoid "Could not determine java version from '21.x'"
JAVA17_CANDIDATE="/usr/lib/jvm/java-17-openjdk-amd64"
if [[ -d "${JAVA17_CANDIDATE}" ]]; then
echo "Using Java 17 from ${JAVA17_CANDIDATE}"
export JAVA_HOME="${JAVA17_CANDIDATE}"
export ORG_GRADLE_JAVA_HOME="${JAVA17_CANDIDATE}"
export PATH="${JAVA17_CANDIDATE}/bin:${PATH}"
else
echo "⚠ Java 17 JDK not found at ${JAVA17_CANDIDATE}. Using system default Java:"
fi
echo "JAVA_HOME=${JAVA_HOME:-<not set>}"
echo "ORG_GRADLE_JAVA_HOME=${ORG_GRADLE_JAVA_HOME:-<not set>}"
java -version || echo "Java not found on PATH builds will likely fail."
echo
OUT_DIR="${ROOT_DIR}/apk_output"
mkdir -p "${OUT_DIR}"
native_apps=(
"OnTime_User_live"
"OnTime_Driver_live"
"OnTime_Merchant_live"
)
flutter_candidates=(
"flutter_user_clone"
"flutter_merchant_clone"
"flutter_driver_clone"
"ontime_user_flutter"
"ontime_merchant_flutter"
"ontime_driver_flutter"
)
declare -a successes=()
declare -a failures=()
build_flutter_apk() {
local app_dir="$1"
echo "========================================"
echo "Building Flutter app in: ${app_dir}"
echo "========================================"
cd "${ROOT_DIR}/${app_dir}"
if ! flutter clean; then
echo "❌ flutter clean failed for ${app_dir}"
failures+=("${app_dir} (flutter clean)")
return 1
fi
if ! flutter pub get; then
echo "❌ flutter pub get failed for ${app_dir}"
failures+=("${app_dir} (flutter pub get)")
return 1
fi
if ! flutter build apk --release; then
echo "❌ flutter build apk failed for ${app_dir}"
failures+=("${app_dir} (flutter build apk)")
return 1
fi
local apk_path="${ROOT_DIR}/${app_dir}/build/app/outputs/flutter-apk/app-release.apk"
local out_name="${app_dir}_flutter-release.apk"
if [[ -f "${apk_path}" ]]; then
cp "${apk_path}" "${OUT_DIR}/${out_name}"
echo "📦 Copied to: ${OUT_DIR}/${out_name}"
else
echo "❌ Flutter release APK not found at: ${apk_path}"
failures+=("${app_dir} (apk missing)")
return 1
fi
echo "✅ Finished building ${app_dir}"
echo
successes+=("${app_dir} (flutter)")
return 0
}
build_native_apk() {
local app_dir="$1"
echo "========================================"
echo "Building native Android app in: ${app_dir}"
echo "========================================"
cd "${ROOT_DIR}/${app_dir}"
if ! ./gradlew "assembleRelease" --no-daemon; then
echo "❌ Gradle build failed for ${app_dir}"
failures+=("${app_dir} (gradle assembleRelease)")
return 1
fi
local apk_path="${ROOT_DIR}/${app_dir}/app/build/outputs/apk/release/app-release.apk"
local out_name="${app_dir}_native-release.apk"
if [[ -f "${apk_path}" ]]; then
cp "${apk_path}" "${OUT_DIR}/${out_name}"
echo "📦 Copied to: ${OUT_DIR}/${out_name}"
else
echo "❌ Native release APK not found at: ${apk_path}"
failures+=("${app_dir} (apk missing)")
return 1
fi
echo "✅ Finished building ${app_dir}"
echo
successes+=("${app_dir} (java)")
return 0
}
main() {
local found_flutter=0
for app in "${flutter_candidates[@]}"; do
if [[ -d "${ROOT_DIR}/${app}" ]]; then
found_flutter=1
build_flutter_apk "${app}" || true
fi
done
if [[ "${found_flutter}" -eq 0 ]]; then
echo "⚠️ No Flutter app directories found from configured candidates."
echo
fi
for app in "${native_apps[@]}"; do
if [[ -d "${ROOT_DIR}/${app}" ]]; then
build_native_apk "${app}" || true
else
echo "⚠️ Skipping ${app}: directory not found at ${ROOT_DIR}/${app}"
failures+=("${app} (directory missing)")
fi
done
echo
echo "========================================"
echo "Build Summary"
echo "========================================"
echo "✅ Success count: ${#successes[@]}"
for item in "${successes[@]}"; do
echo " - ${item}"
done
echo "❌ Failure count: ${#failures[@]}"
for item in "${failures[@]}"; do
echo " - ${item}"
done
echo
echo "APK output directory: ${OUT_DIR}"
if [[ "${#failures[@]}" -gt 0 ]]; then
exit 1
fi
echo "🎉 All builds completed successfully."
}
main "$@"