Skip to content

Instantly share code, notes, and snippets.

@minademian
Created November 28, 2025 08:01
Show Gist options
  • Select an option

  • Save minademian/6e841c8e1a84308c6b3dc937a2d4a4cd to your computer and use it in GitHub Desktop.

Select an option

Save minademian/6e841c8e1a84308c6b3dc937a2d4a4cd to your computer and use it in GitHub Desktop.
Verify Android APK Bundles Before Publishing to Google Play Store
#!/usr/bin/env bash
# verify_apk_release.sh
# Pre-publish hook for Android Release APKs with 16KB pagesize and arm64-only ABI support
# Usage: ./verify_apk_release.sh
set -euo pipefail
ANDROID_DIR="./android"
BUILD_DIR="$ANDROID_DIR/app/build/outputs/apk/release"
APK_FILE="$BUILD_DIR/app-release.apk"
NDK_HOME="$ANDROID_HOME/ndk/26.1.10909125"
if [[ ! -f "$APK_FILE" ]]; then
echo "[ERROR] Release APK not found at $APK_FILE. Please build the release APK first."
exit 1
fi
READELF_BIN="$NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-readelf"
echo $READELF_BIN
if [[ ! -x "$READELF_BIN" ]]; then
echo "[ERROR] llvm-readelf not found. Please install LLVM via Homebrew: brew install llvm"
exit 1
fi
echo "[hook] Starting pre-publish verification..."
echo "[hook] Checking ABI content in APK..."
unzip -l "$APK_FILE" | grep "lib/" > /tmp/apk_libs.txt
if grep -qv "lib/arm64-v8a/" /tmp/apk_libs.txt; then
echo "[ERROR] Found non-arm64-v8a ABIs in APK!"
grep -v "lib/arm64-v8a/" /tmp/apk_libs.txt
exit 1
else
echo "[hook] ✅ Only arm64-v8a found."
fi
echo "[hook] Verifying ELF max page size (16384)..."
TMP_EXTRACT="/tmp/apk_extract"
rm -rf "$TMP_EXTRACT"
mkdir -p "$TMP_EXTRACT"
echo "[hook] Extracting APK contents to $TMP_EXTRACT..."
unzip -q "$APK_FILE" -d "$TMP_EXTRACT"
SO_FILES=()
while IFS= read -r line; do
SO_FILES+=("$line")
done < <(find "$TMP_EXTRACT" -path "*/lib/arm64-v8a/*.so")
echo "[hook] Found ${#SO_FILES[@]} .so files to check."
FAILED=0
for lib in /tmp/apk_extract/lib/arm64-v8a/*.so; do
align=$(llvm-readelf -l $lib | awk '/LOAD/ {print $NF}' | sort -nr | head -n1)
if [[ "$align" != "0x4000" ]]; then
echo "❌ $lib has Align=$align"
FAILED=1
else
echo "✅ $lib has MaxPageSize=16384"
fi
done
if [[ $FAILED -eq 0 ]]; then
echo "[hook] ✅ All .so files have MaxPageSize=16384"
else
exit 1
fi
echo "[hook] Pre-publish verification passed."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment