chore(scripts): fix up

This commit is contained in:
devthejo 2025-10-01 22:35:14 +02:00
parent 39d2985075
commit 9ea614907e
No known key found for this signature in database
GPG key ID: 00CCA7A92B1D5351
6 changed files with 159 additions and 27 deletions

View file

@ -1,32 +1,75 @@
#!/bin/bash
#!/usr/bin/env bash
set -euo pipefail
set -e
# Repo root (this script lives at repo root)
ROOT_DIR="$(cd "$(dirname "$0")"; pwd)"
# Check if DEVICE environment variable is set
# Auto-pick a single target device if DEVICE not provided
DEVICE="${DEVICE:-}"
if [ -z "$DEVICE" ]; then
echo "Error: DEVICE environment variable is not set."
echo "Usage: DEVICE=emulator-5554 ./install-android.sh"
EMU=$(adb devices | awk '/^emulator-/{print $1}' | head -n1)
USB=$(adb devices -l | awk '/ device usb:/{print $1}' | head -n1)
if [ -n "$EMU" ] && [ -z "$USB" ]; then DEVICE="$EMU"; fi
if [ -n "$USB" ] && [ -z "$EMU" ]; then DEVICE="$USB"; fi
fi
if [ -z "$DEVICE" ]; then
echo "Error: DEVICE not set and could not auto-detect a single target." >&2
echo "Usage: DEVICE=<adb-serial> ./install-android.sh [AAB_PATH]" >&2
exit 1
fi
# Navigate to the bundle release directory
cd android/app/build/outputs/bundle/release
# Optional first arg: override AAB path, otherwise auto-detect newest release AAB
AAB_PATH="${1:-}"
if [ -z "$AAB_PATH" ]; then
AAB_PATH="$("$ROOT_DIR/scripts/find-latest-aab.sh")"
fi
# Build APKs with signing
java -jar /opt/bundletool-all-1.17.1.jar build-apks \
--mode universal \
--bundle ./app-release.aab \
--output ./app.apks \
--ks $PWD/../../../../debug.keystore \
if [ ! -f "$AAB_PATH" ]; then
echo "AAB not found: $AAB_PATH" >&2
exit 1
fi
# Bundletool path (override with BUNDLETOOL=/path/to/bundletool.jar)
BUNDLETOOL="${BUNDLETOOL:-/opt/bundletool-all-1.17.1.jar}"
# Temp output dir
OUT_DIR="$(mktemp -d)"
APKS_PATH="$OUT_DIR/app.apks"
echo "Target device: $DEVICE"
echo "Using AAB: $AAB_PATH"
echo "Bundletool: $BUNDLETOOL"
# Default: generate APKs optimized for the connected device.
# Set CONNECTED_DEVICE=0 to force universal APK generation/install.
if [ "${CONNECTED_DEVICE:-1}" = "1" ]; then
echo "Building device-optimized APKs for connected device..."
java -jar "$BUNDLETOOL" build-apks \
--connected-device \
--bundle "$AAB_PATH" \
--output "$APKS_PATH" \
--ks "$ROOT_DIR/android/app/debug.keystore" \
--ks-pass pass:android \
--ks-key-alias androiddebugkey \
--key-pass pass:android
# Convert .apks to .zip and extract
mv app.apks app.zip
unzip -o app.zip
echo "Installing APKs to $DEVICE..."
java -jar "$BUNDLETOOL" install-apks --device-id "$DEVICE" --apks "$APKS_PATH"
else
echo "Building universal APK..."
java -jar "$BUNDLETOOL" build-apks \
--mode universal \
--bundle "$AAB_PATH" \
--output "$APKS_PATH" \
--ks "$ROOT_DIR/android/app/debug.keystore" \
--ks-pass pass:android \
--ks-key-alias androiddebugkey \
--key-pass pass:android
# Install the APK on the device
adb -s $DEVICE install universal.apk
echo "Extracting and installing universal APK..."
unzip -o "$APKS_PATH" -d "$OUT_DIR" >/dev/null
adb -s "$DEVICE" install -r "$OUT_DIR/universal.apk"
fi
echo "Installation complete!"
echo "Installation complete on $DEVICE"

View file

@ -184,9 +184,10 @@
94EB5593B5404563AA1FB51E /* Fix Xcode 15 Bug */,
976C0290112E4DD89069ADCE /* Fix Xcode 15 Bug */,
F20775C6FC44408A83E9F518 /* Fix Xcode 15 Bug */,
B5B86888E2F141A1A81CBEB3 /* Remove signature files (Xcode workaround) */,
B7EB6314B4ED4D5AB13DB309 /* Fix Xcode 15 Bug */,
850BF46CA013409EB7CF4BEC /* Remove signature files (Xcode workaround) */,
6261F4CAFAC24C76A6BFFF3F /* Fix Xcode 15 Bug */,
4B2001AC853541C9B3B9335B /* Remove signature files (Xcode workaround) */,
);
buildRules = (
);
@ -1347,6 +1348,40 @@ fi";
shellScript = "
echo \"Remove signature files (Xcode workaround)\";
rm -rf \"$CONFIGURATION_BUILD_DIR/MapLibre.xcframework-ios.signature\";
";
};
6261F4CAFAC24C76A6BFFF3F /* Fix Xcode 15 Bug */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
name = "Fix Xcode 15 Bug";
inputPaths = (
);
outputPaths = (
);
shellPath = /bin/sh;
shellScript = "if [ \"$XCODE_VERSION_MAJOR\" = \"1500\" ]; then
echo \"Remove signature files (Xcode 15 workaround)\"
find \"$BUILD_DIR/${CONFIGURATION}-iphoneos\" -name \"*.signature\" -type f | xargs -r rm
fi";
};
4B2001AC853541C9B3B9335B /* Remove signature files (Xcode workaround) */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
name = "Remove signature files (Xcode workaround)";
inputPaths = (
);
outputPaths = (
);
shellPath = /bin/sh;
shellScript = "
echo \"Remove signature files (Xcode workaround)\";
rm -rf \"$CONFIGURATION_BUILD_DIR/MapLibre.xcframework-ios.signature\";
";
};
/* End PBXShellScriptBuildPhase section */

View file

@ -11,7 +11,7 @@
"android:prod": "dotenv --override -e .env.prod -- expo run:android",
"bundle:android": "dotenv --override -e .env.prod -- bundle-android",
"bundle:android:fastdev": "SENTRY_ALLOW_FAILURE=true SENTRY_AUTH_TOKEN='' yarn bundle:android",
"bundle:android:upload:internal": "fastlane supply --aab android/app/build/outputs/bundle/release/app-release.aab --track internal -j keys/alerte-secours-449609-469f820e5960.json -p com.alertesecours",
"bundle:android:upload:internal": "./scripts/upload-android-internal.sh",
"bundle:ios:archive": "./scripts/ios-archive.sh",
"bundle:ios:export": "./scripts/ios-export.sh",
"bundle:ios:upload": "./scripts/ios-upload.sh",

View file

@ -14,6 +14,8 @@ cd $ROOT_WD
rm -rf android/app/build/generated/*
cd android
./gradlew bundleRelease
./gradlew :app:bundleDeviceArm64Release
cd "$ROOT_WD"
AAB_PATH="$("$ROOT_WD/scripts/find-latest-aab.sh")"
echo "find your bundle here: file://./android/app/build/outputs/bundle/release/app-release.aab"
echo "find your bundle here: file://$AAB_PATH"

19
scripts/find-latest-aab.sh Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail
# Always operate from repo root
ROOT_DIR="$(cd "$(dirname "$0")/.."; pwd)"
cd "$ROOT_DIR"
# Try to find the most recent release AAB regardless of variant (deviceArm64Release, emulatorX86_64Release, universalRelease, etc.)
set +e
LATEST=$(ls -t android/app/build/outputs/bundle/*Release/app-*-release.aab 2>/dev/null | head -n1)
set -e
if [ -z "${LATEST:-}" ]; then
echo "No AABs found under android/app/build/outputs/bundle/*Release" >&2
echo "Hint: run: ./gradlew :app:bundleDeviceArm64Release (or your desired variant)" >&2
exit 1
fi
echo "$LATEST"

View file

@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -euo pipefail
# Root of repo
ROOT_DIR="$(cd "$(dirname "$0")/.."; pwd)"
# Allow passing an explicit AAB path as first arg, otherwise auto-detect latest
AAB_PATH="${1:-}"
if [ -z "$AAB_PATH" ]; then
AAB_PATH="$("$ROOT_DIR/scripts/find-latest-aab.sh")"
fi
if [ ! -f "$AAB_PATH" ]; then
echo "AAB not found: $AAB_PATH" >&2
exit 1
fi
# Configurable via env, with sensible defaults
JSON_KEY_PATH="${GOOGLE_JSON_KEY_PATH:-keys/alerte-secours-449609-469f820e5960.json}"
PACKAGE_NAME="${PACKAGE_NAME:-com.alertesecours}"
TRACK="${TRACK:-internal}"
echo "Uploading AAB:"
echo " File: $AAB_PATH"
echo " Package: $PACKAGE_NAME"
echo " Track: $TRACK"
echo " Service acct: $JSON_KEY_PATH"
exec fastlane supply \
--aab "$AAB_PATH" \
--track "$TRACK" \
-j "$JSON_KEY_PATH" \
-p "$PACKAGE_NAME"