#!/bin/bash
set -e
VERSION=$(jq -r '.version' package.json)
MANIFEST="./src-tauri/gen/android/app/src/main/AndroidManifest.xml"
INSTALL_PERMISSION_LINE=''
STORAGE_PERMISSION_LINE=''
ised() {
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "$@"
else
sed -i "$@"
fi
return $?
}
# --- REMOVE PERMISSION BEFORE BUILD ---
if grep -q 'REQUEST_INSTALL_PACKAGES' "$MANIFEST"; then
echo "๐งน Removing REQUEST_INSTALL_PACKAGES from AndroidManifest.xml"
if ised "/REQUEST_INSTALL_PACKAGES/d" "$MANIFEST"; then
echo "โ
Successfully removed REQUEST_INSTALL_PACKAGES"
else
echo "โ Failed to remove REQUEST_INSTALL_PACKAGES" >&2
exit 1
fi
fi
if grep -q 'MANAGE_EXTERNAL_STORAGE' "$MANIFEST"; then
echo "๐งน Removing MANAGE_EXTERNAL_STORAGE from AndroidManifest.xml"
if ised "/MANAGE_EXTERNAL_STORAGE/d" "$MANIFEST"; then
echo "โ
Successfully removed MANAGE_EXTERNAL_STORAGE"
else
echo "โ Failed to remove MANAGE_EXTERNAL_STORAGE" >&2
exit 1
fi
fi
echo "๐ Running: pnpm tauri android build"
pnpm tauri android build --config src-tauri/tauri.playstore.conf.json
# --- ADD PERMISSION BACK AFTER BUILD ---
if ! grep -q 'REQUEST_INSTALL_PACKAGES' "$MANIFEST"; then
echo "โป๏ธ Restoring REQUEST_INSTALL_PACKAGES in AndroidManifest.xml"
ised "/android.permission.INTERNET/a\\
$INSTALL_PERMISSION_LINE
" "$MANIFEST"
fi
if ! grep -q 'MANAGE_EXTERNAL_STORAGE' "$MANIFEST"; then
echo "โป๏ธ Restoring MANAGE_EXTERNAL_STORAGE in AndroidManifest.xml"
ised "/android.permission.WRITE_EXTERNAL_STORAGE/a\\
$STORAGE_PERMISSION_LINE
" "$MANIFEST"
fi
source .env.google-play.local
if [[ -z "$GOOGLE_PLAY_JSON_KEY_FILE" ]]; then
echo "โ GOOGLE_PLAY_JSON_KEY_FILE is not set"
exit 1
fi
cd ../../
fastlane android upload_production