Files
IdP/tauri_app/docker/prefetch-android-agp.sh
lendry 8805ec327f fix
2026-06-26 20:39:41 +03:00

67 lines
2.1 KiB
Bash
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
# Pre-download Android Gradle Plugin into a local Maven repo inside the image.
set -euo pipefail
AGP_VERSION="${ANDROID_GRADLE_PLUGIN_VERSION:-8.11.0}"
LOCAL_REPO="${ANDROID_AGP_LOCAL_REPO:-/opt/android-agp-maven}"
BUNDLED_REPO="${ANDROID_AGP_BUNDLED_REPO:-/workspace/tauri_app/docker/offline-maven}"
BUNDLED_ARTIFACT="${BUNDLED_REPO}/com/android/tools/build/gradle/${AGP_VERSION}/gradle-${AGP_VERSION}.jar"
copy_bundled() {
if [ ! -f "${BUNDLED_ARTIFACT}" ]; then
return 1
fi
mkdir -p "${LOCAL_REPO}"
cp -a "${BUNDLED_REPO}/." "${LOCAL_REPO}/"
echo "==> AGP ${AGP_VERSION} copied from bundled offline cache (${BUNDLED_REPO})"
return 0
}
try_download() {
local base_url="$1"
local dest_dir="${LOCAL_REPO}/com/android/tools/build/gradle/${AGP_VERSION}"
mkdir -p "${dest_dir}"
if curl -fsSL --connect-timeout 20 --max-time 120 \
"${base_url}/com/android/tools/build/gradle/${AGP_VERSION}/gradle-${AGP_VERSION}.pom" \
-o "${dest_dir}/gradle-${AGP_VERSION}.pom"; then
curl -fsSL --connect-timeout 20 --max-time 600 \
"${base_url}/com/android/tools/build/gradle/${AGP_VERSION}/gradle-${AGP_VERSION}.jar" \
-o "${dest_dir}/gradle-${AGP_VERSION}.jar"
echo "${base_url}"
return 0
fi
return 1
}
echo "==> Prefetch Android Gradle Plugin ${AGP_VERSION}"
if copy_bundled; then
exit 0
fi
MIRROR=""
for base in \
"https://maven.google.com" \
"https://dl.google.com/android/maven2" \
"https://dl.google.com/dl/android/maven2"; do
if MIRROR="$(try_download "${base}")"; then
echo "==> AGP ${AGP_VERSION} cached from ${MIRROR}"
break
fi
done
if [ -z "${MIRROR}" ]; then
echo "Не удалось получить Android Gradle Plugin ${AGP_VERSION}." >&2
echo "Нет bundled-кэша в ${BUNDLED_REPO} и Google Maven недоступен (404/сеть)." >&2
echo "На машине с интернетом выполните: tauri_app/docker/populate-offline-agp.sh" >&2
exit 1
fi
cat > "${LOCAL_REPO}/README.txt" <<EOF
Local cache for com.android.tools.build:gradle:${AGP_VERSION}
Source: ${MIRROR}
EOF
echo "==> Local AGP repo: ${LOCAL_REPO}"