build: remove expo.dev/EAS dependency, add local Android build pipeline
- Delete eas.json and strip extra.eas.projectId from app.json - Add plugins/withAndroidReleaseSigning.js — Expo config plugin that injects release signingConfig into the generated build.gradle during expo prebuild - Add build-apk.sh — self-contained build script (expo prebuild + Gradle) Reads keystore credentials from ~/.config/postiz-mobile/signing.env Outputs APK/AAB to dist/, wipes credentials from gradle.properties after build - Add install-android-sdk.sh — one-time Android SDK cmdline-tools bootstrap - Remove unused expo-task-manager dependency - Update .gitignore: android/, ios/, static-build/ excluded (generated) Build workflow: 1. eas credentials --platform android # export keystore once 2. ./install-android-sdk.sh # first time only 3. ./build-apk.sh # → dist/postiz-mobile-YYYYMMDD-HHMM.apk Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Executable
+115
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env bash
|
||||
# build-apk.sh — Build a signed release APK locally without expo.dev / EAS.
|
||||
#
|
||||
# Prerequisites (first time only):
|
||||
# 1. Export EAS keystore:
|
||||
# eas credentials --platform android
|
||||
# → "Download existing keystore" → save to ~/.config/postiz-mobile/postiz-mobile.jks
|
||||
# 2. Fill in signing credentials:
|
||||
# cp ~/.config/postiz-mobile/signing.env.example ~/.config/postiz-mobile/signing.env
|
||||
# editor ~/.config/postiz-mobile/signing.env
|
||||
# 3. Install Android SDK (if not already):
|
||||
# ./install-android-sdk.sh
|
||||
#
|
||||
# Usage:
|
||||
# ./build-apk.sh # APK goes to dist/
|
||||
# ./build-apk.sh --aab # AAB (Play Store) instead of APK
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SIGNING_ENV="$HOME/.config/postiz-mobile/signing.env"
|
||||
DIST_DIR="$SCRIPT_DIR/dist"
|
||||
BUILD_TYPE="${1:-}"
|
||||
|
||||
# ─── Colours ───────────────────────────────────────────────────────────────
|
||||
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
|
||||
info() { echo -e "${GREEN}[build]${NC} $*"; }
|
||||
warn() { echo -e "${YELLOW}[warn]${NC} $*"; }
|
||||
abort() { echo -e "${RED}[error]${NC} $*" >&2; exit 1; }
|
||||
|
||||
# ─── 1. Signing credentials ────────────────────────────────────────────────
|
||||
if [ ! -f "$SIGNING_ENV" ]; then
|
||||
abort "Missing signing.env.\n\n cp ~/.config/postiz-mobile/signing.env.example ~/.config/postiz-mobile/signing.env\n # then fill in your keystore path and passwords"
|
||||
fi
|
||||
# shellcheck source=/dev/null
|
||||
source "$SIGNING_ENV"
|
||||
|
||||
[ -z "${KEYSTORE_PATH:-}" ] && abort "KEYSTORE_PATH not set in signing.env"
|
||||
[ -z "${KEYSTORE_ALIAS:-}" ] && abort "KEYSTORE_ALIAS not set in signing.env"
|
||||
[ -z "${KEYSTORE_STORE_PASSWORD:-}" ] && abort "KEYSTORE_STORE_PASSWORD not set in signing.env"
|
||||
[ -z "${KEYSTORE_KEY_PASSWORD:-}" ] && abort "KEYSTORE_KEY_PASSWORD not set in signing.env"
|
||||
|
||||
KEYSTORE_PATH_EXPANDED="${KEYSTORE_PATH/#\$HOME/$HOME}"
|
||||
KEYSTORE_PATH_EXPANDED="${KEYSTORE_PATH_EXPANDED/#~/$HOME}"
|
||||
|
||||
[ ! -f "$KEYSTORE_PATH_EXPANDED" ] && abort "Keystore not found: $KEYSTORE_PATH_EXPANDED\n\nExport it from EAS:\n eas credentials --platform android\n → Download existing keystore → save to $KEYSTORE_PATH_EXPANDED"
|
||||
|
||||
# ─── 2. Android SDK ────────────────────────────────────────────────────────
|
||||
if [ -z "${ANDROID_HOME:-}" ]; then
|
||||
# Try common locations
|
||||
for candidate in "$HOME/android-sdk" "$HOME/Android/Sdk" "/opt/android-sdk"; do
|
||||
if [ -d "$candidate/platform-tools" ]; then
|
||||
export ANDROID_HOME="$candidate"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -z "${ANDROID_HOME:-}" ]; then
|
||||
abort "Android SDK not found.\n\nRun: ./install-android-sdk.sh\nOr set ANDROID_HOME manually in your shell."
|
||||
fi
|
||||
|
||||
export PATH="$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/latest/bin"
|
||||
info "Android SDK: $ANDROID_HOME"
|
||||
|
||||
# ─── 3. expo prebuild ──────────────────────────────────────────────────────
|
||||
info "Running expo prebuild (Android)…"
|
||||
cd "$SCRIPT_DIR"
|
||||
pnpm exec expo prebuild --platform android --clean --no-install
|
||||
|
||||
# ─── 4. Inject signing into gradle.properties ──────────────────────────────
|
||||
info "Injecting signing credentials into gradle.properties…"
|
||||
GRADLE_PROPS="$SCRIPT_DIR/android/gradle.properties"
|
||||
|
||||
# Remove any previous signing block written by this script
|
||||
sed -i '/^# --- postiz-mobile release signing/,/^# --- end signing/d' "$GRADLE_PROPS" 2>/dev/null || true
|
||||
|
||||
cat >> "$GRADLE_PROPS" << EOF
|
||||
|
||||
# --- postiz-mobile release signing (injected by build-apk.sh)
|
||||
MYAPP_UPLOAD_STORE_FILE=$KEYSTORE_PATH_EXPANDED
|
||||
MYAPP_UPLOAD_STORE_PASSWORD=$KEYSTORE_STORE_PASSWORD
|
||||
MYAPP_UPLOAD_KEY_ALIAS=$KEYSTORE_ALIAS
|
||||
MYAPP_UPLOAD_KEY_PASSWORD=$KEYSTORE_KEY_PASSWORD
|
||||
# --- end signing
|
||||
EOF
|
||||
|
||||
# ─── 5. Gradle build ───────────────────────────────────────────────────────
|
||||
cd "$SCRIPT_DIR/android"
|
||||
|
||||
if [ "$BUILD_TYPE" = "--aab" ]; then
|
||||
info "Building AAB (release)…"
|
||||
./gradlew bundleRelease
|
||||
ARTIFACT="app/build/outputs/bundle/release/app-release.aab"
|
||||
EXT="aab"
|
||||
else
|
||||
info "Building APK (release)…"
|
||||
./gradlew assembleRelease
|
||||
ARTIFACT="app/build/outputs/apk/release/app-release.apk"
|
||||
EXT="apk"
|
||||
fi
|
||||
|
||||
# ─── 6. Copy to dist/ ──────────────────────────────────────────────────────
|
||||
mkdir -p "$DIST_DIR"
|
||||
TIMESTAMP="$(date +%Y%m%d-%H%M)"
|
||||
OUTPUT="$DIST_DIR/postiz-mobile-$TIMESTAMP.$EXT"
|
||||
cp "$ARTIFACT" "$OUTPUT"
|
||||
|
||||
echo ""
|
||||
info "Build complete!"
|
||||
echo -e " ${GREEN}→ $OUTPUT${NC}"
|
||||
echo ""
|
||||
|
||||
# Wipe signing credentials from gradle.properties for safety
|
||||
sed -i '/^# --- postiz-mobile release signing/,/^# --- end signing/d' "$GRADLE_PROPS"
|
||||
Reference in New Issue
Block a user