Skip to content

Instantly share code, notes, and snippets.

@nickfrosty
Created October 1, 2025 01:07
Show Gist options
  • Select an option

  • Save nickfrosty/8481404a629d5db87f7524ad4b937915 to your computer and use it in GitHub Desktop.

Select an option

Save nickfrosty/8481404a629d5db87f7524ad4b937915 to your computer and use it in GitHub Desktop.
Check and validate's your system to ensure you have the required tooling in order to sign APK builds of Android apps to be published on the Solana Mobile's dApp store (per this guide https://docs.solanamobile.com/dapp-publishing/building-expo-apk on Sept 30, 2025)
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo "=== Android SDK Environment Check ==="
echo ""
# Check if JAVA_HOME is set and java is available
echo "1. Checking Java installation..."
JAVA_OK=false
if command -v java &> /dev/null; then
JAVA_VERSION=$(java -version 2>&1 | head -n 1)
echo -e "${GREEN}✓ Java is available in PATH${NC}"
echo " $JAVA_VERSION"
JAVA_OK=true
else
echo -e "${RED}✗ Java command not found in PATH${NC}"
fi
echo ""
echo "2. Checking JAVA_HOME environment variable..."
if [ -z "$JAVA_HOME" ]; then
echo -e "${YELLOW}⚠ JAVA_HOME is not set${NC}"
if [ "$JAVA_OK" = true ]; then
echo " Java is available but JAVA_HOME is not set"
echo " Android SDK tools may not work properly without JAVA_HOME"
echo ""
# Try to detect Java home
JAVA_PATH=$(which java)
JAVA_HOME_DETECTED=$(readlink -f "$JAVA_PATH" | sed 's:/bin/java::')
echo " Detected Java installation at:"
echo " $JAVA_HOME_DETECTED"
echo ""
# Detect shell
SHELL_CONFIG=""
if [ -n "$BASH_VERSION" ]; then
SHELL_CONFIG="$HOME/.bashrc"
elif [ -n "$ZSH_VERSION" ]; then
SHELL_CONFIG="$HOME/.zshrc"
else
case "$SHELL" in
*/bash)
SHELL_CONFIG="$HOME/.bashrc"
;;
*/zsh)
SHELL_CONFIG="$HOME/.zshrc"
;;
*)
SHELL_CONFIG="$HOME/.bashrc"
;;
esac
fi
read -p " Add JAVA_HOME to $SHELL_CONFIG automatically? (y/N): " ADD_JAVA_HOME
if [ "$ADD_JAVA_HOME" = "y" ] || [ "$ADD_JAVA_HOME" = "Y" ]; then
# Check if JAVA_HOME already exists in the file
if grep -q "export JAVA_HOME=" "$SHELL_CONFIG" 2>/dev/null; then
echo -e "${YELLOW} JAVA_HOME export already exists in $SHELL_CONFIG${NC}"
echo " Please update it manually to:"
echo " export JAVA_HOME=$JAVA_HOME_DETECTED"
else
echo "" >> "$SHELL_CONFIG"
echo "# Java home" >> "$SHELL_CONFIG"
echo "export JAVA_HOME=$JAVA_HOME_DETECTED" >> "$SHELL_CONFIG"
echo -e "${GREEN}✓ Added to $SHELL_CONFIG${NC}"
fi
# Source the config file to apply changes immediately
echo ""
echo " Applying changes to current session..."
source "$SHELL_CONFIG"
# Verify JAVA_HOME is now set
if [ -n "$JAVA_HOME" ]; then
echo -e "${GREEN}✓ JAVA_HOME is now set: $JAVA_HOME${NC}"
else
echo -e "${RED}✗ Failed to set JAVA_HOME${NC}"
echo " Try running: source $SHELL_CONFIG"
exit 1
fi
else
echo ""
echo " Manual setup required:"
echo " 1. Add this line to $SHELL_CONFIG:"
echo " export JAVA_HOME=$JAVA_HOME_DETECTED"
echo ""
echo " 2. Then run: source $SHELL_CONFIG"
echo ""
read -p " Continue without setting JAVA_HOME? (y/N): " CONTINUE_WITHOUT_JAVA_HOME
if [ "$CONTINUE_WITHOUT_JAVA_HOME" != "y" ] && [ "$CONTINUE_WITHOUT_JAVA_HOME" != "Y" ]; then
exit 1
fi
fi
else
echo " Java is not installed or not in PATH"
echo ""
echo " RECOMMENDED: Download latest JDK from Oracle:"
echo " https://www.oracle.com/java/technologies/downloads/"
echo ""
echo " Alternative - Install via package manager:"
echo " - Ubuntu/Debian: sudo apt install openjdk-17-jdk"
echo " - Fedora: sudo dnf install java-17-openjdk-devel"
echo " - Arch: sudo pacman -S jdk-openjdk"
echo ""
echo -e "${YELLOW} After installation, set JAVA_HOME in ~/.bashrc or ~/.zshrc:${NC}"
echo " export JAVA_HOME=/path/to/your/jdk"
echo " Example: export JAVA_HOME=/usr/lib/jvm/jdk-21"
exit 1
fi
else
echo -e "${GREEN}✓ JAVA_HOME is set: $JAVA_HOME${NC}"
# Verify JAVA_HOME points to a valid directory
if [ ! -d "$JAVA_HOME" ]; then
echo -e "${RED}✗ JAVA_HOME directory does not exist: $JAVA_HOME${NC}"
exit 1
fi
# Check if JAVA_HOME/bin/java exists
if [ -f "$JAVA_HOME/bin/java" ]; then
echo -e "${GREEN}✓ Java binary found in JAVA_HOME${NC}"
else
echo -e "${RED}✗ Java binary not found at: $JAVA_HOME/bin/java${NC}"
exit 1
fi
fi
echo ""
# Check if ANDROID_HOME is set
echo "3. Checking ANDROID_HOME environment variable..."
if [ -z "$ANDROID_HOME" ]; then
echo -e "${RED}✗ ANDROID_HOME is not set${NC}"
echo " Please set ANDROID_HOME in your shell configuration file (~/.bashrc or ~/.zshrc)"
echo " Example: export ANDROID_HOME=\$HOME/Android/Sdk"
exit 1
else
echo -e "${GREEN}✓ ANDROID_HOME is set: $ANDROID_HOME${NC}"
fi
echo ""
# Check if ANDROID_HOME directory exists
echo "4. Checking if ANDROID_HOME directory exists..."
if [ ! -d "$ANDROID_HOME" ]; then
echo -e "${RED}✗ Directory does not exist: $ANDROID_HOME${NC}"
echo " Please create the Android SDK directory or update ANDROID_HOME"
exit 1
else
echo -e "${GREEN}✓ Directory exists: $ANDROID_HOME${NC}"
fi
echo ""
# Check if cmdline-tools directory exists
echo "5. Checking for command-line tools directory..."
CMDLINE_TOOLS_DIR="$ANDROID_HOME/cmdline-tools/latest"
if [ ! -d "$CMDLINE_TOOLS_DIR" ]; then
echo -e "${RED}✗ Command-line tools not found at: $CMDLINE_TOOLS_DIR${NC}"
echo " The Android SDK command-line tools are not installed"
echo ""
echo " Download from: https://developer.android.com/studio#command-line-tools-only"
echo ""
read -p " Enter the path to the downloaded command-line tools zip file (or 'q' to quit): " ZIP_PATH
if [ "$ZIP_PATH" = "q" ] || [ "$ZIP_PATH" = "Q" ]; then
echo " Installation cancelled"
exit 1
fi
# Expand tilde to home directory
ZIP_PATH="${ZIP_PATH/#\~/$HOME}"
if [ ! -f "$ZIP_PATH" ]; then
echo -e "${RED}✗ File not found: $ZIP_PATH${NC}"
exit 1
fi
echo ""
read -p " Enter the SHA-256 checksum from the website (or press Enter to skip): " EXPECTED_CHECKSUM
if [ ! -z "$EXPECTED_CHECKSUM" ]; then
echo ""
echo " Verifying checksum..."
# Calculate actual checksum and normalize to lowercase
ACTUAL_CHECKSUM=$(sha256sum "$ZIP_PATH" | awk '{print $1}' | tr '[:upper:]' '[:lower:]')
# Normalize expected checksum to lowercase and trim whitespace
EXPECTED_CHECKSUM=$(echo "$EXPECTED_CHECKSUM" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
echo " Expected: $EXPECTED_CHECKSUM"
echo " Actual: $ACTUAL_CHECKSUM"
echo ""
if [ "$ACTUAL_CHECKSUM" = "$EXPECTED_CHECKSUM" ]; then
echo -e "${GREEN}✓ Checksum verified${NC}"
else
echo -e "${RED}✗ Checksum mismatch!${NC}"
echo ""
echo -e "${YELLOW} This could mean:${NC}"
echo " - The file was not downloaded completely"
echo " - The file was corrupted during download"
echo " - You downloaded a different version than expected"
echo ""
read -p " Continue anyway? (y/N): " CONTINUE
if [ "$CONTINUE" != "y" ] && [ "$CONTINUE" != "Y" ]; then
echo " Installation cancelled"
exit 1
fi
fi
else
echo -e "${YELLOW}⚠ Skipping checksum verification${NC}"
fi
echo ""
echo " Installing command-line tools..."
# Create cmdline-tools directory
mkdir -p "$ANDROID_HOME/cmdline-tools"
# Extract the zip file
unzip -q "$ZIP_PATH" -d "$ANDROID_HOME/cmdline-tools"
if [ $? -ne 0 ]; then
echo -e "${RED}✗ Failed to extract zip file${NC}"
exit 1
fi
# Move cmdline-tools to latest
if [ -d "$ANDROID_HOME/cmdline-tools/cmdline-tools" ]; then
mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest"
echo -e "${GREEN}✓ Command-line tools installed successfully${NC}"
else
echo -e "${RED}✗ Unexpected zip structure${NC}"
exit 1
fi
echo ""
echo " Continuing with checks..."
echo ""
else
echo -e "${GREEN}✓ Command-line tools directory exists: $CMDLINE_TOOLS_DIR${NC}"
fi
echo ""
# Check if sdkmanager exists
echo "6. Checking for sdkmanager binary..."
SDKMANAGER_PATH="$CMDLINE_TOOLS_DIR/bin/sdkmanager"
if [ ! -f "$SDKMANAGER_PATH" ]; then
echo -e "${RED}✗ sdkmanager not found at: $SDKMANAGER_PATH${NC}"
echo " Command-line tools may be corrupted or incorrectly installed"
exit 1
else
echo -e "${GREEN}✓ sdkmanager found: $SDKMANAGER_PATH${NC}"
fi
echo ""
# Check if sdkmanager is executable
echo "7. Checking if sdkmanager is executable..."
if [ ! -x "$SDKMANAGER_PATH" ]; then
echo -e "${YELLOW}⚠ sdkmanager is not executable${NC}"
echo " Attempting to fix permissions..."
chmod +x "$SDKMANAGER_PATH"
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Permissions fixed${NC}"
else
echo -e "${RED}✗ Failed to fix permissions${NC}"
exit 1
fi
else
echo -e "${GREEN}✓ sdkmanager is executable${NC}"
fi
echo ""
# Check if sdkmanager is in PATH
echo "8. Checking if sdkmanager is in PATH..."
if command -v sdkmanager &> /dev/null; then
SDKMANAGER_VERSION=$(sdkmanager --version 2>&1)
echo -e "${GREEN}✓ sdkmanager is in PATH${NC}"
echo " Version: $SDKMANAGER_VERSION"
else
echo -e "${YELLOW}⚠ sdkmanager is not in PATH${NC}"
echo ""
# Detect shell
SHELL_CONFIG=""
if [ -n "$BASH_VERSION" ]; then
SHELL_CONFIG="$HOME/.bashrc"
elif [ -n "$ZSH_VERSION" ]; then
SHELL_CONFIG="$HOME/.zshrc"
else
# Try to detect based on SHELL environment variable
case "$SHELL" in
*/bash)
SHELL_CONFIG="$HOME/.bashrc"
;;
*/zsh)
SHELL_CONFIG="$HOME/.zshrc"
;;
*)
SHELL_CONFIG="$HOME/.bashrc"
;;
esac
fi
echo " The following needs to be added to your PATH:"
echo " export PATH=\$PATH:\$ANDROID_HOME/cmdline-tools/latest/bin"
echo ""
read -p " Add this to $SHELL_CONFIG automatically? (y/N): " ADD_TO_PATH
if [ "$ADD_TO_PATH" = "y" ] || [ "$ADD_TO_PATH" = "Y" ]; then
# Check if the export already exists in the file
if grep -q "ANDROID_HOME/cmdline-tools/latest/bin" "$SHELL_CONFIG" 2>/dev/null; then
echo -e "${YELLOW} Path already exists in $SHELL_CONFIG${NC}"
else
echo "" >> "$SHELL_CONFIG"
echo "# Android SDK command-line tools" >> "$SHELL_CONFIG"
echo "export PATH=\$PATH:\$ANDROID_HOME/cmdline-tools/latest/bin" >> "$SHELL_CONFIG"
echo -e "${GREEN}✓ Added to $SHELL_CONFIG${NC}"
fi
# Source the config file to apply changes immediately
echo ""
echo " Applying changes to current session..."
source "$SHELL_CONFIG"
echo " Verifying sdkmanager is now accessible..."
if command -v sdkmanager &> /dev/null; then
SDKMANAGER_VERSION=$(sdkmanager --version 2>&1)
echo -e "${GREEN}✓ sdkmanager is now in PATH${NC}"
echo " Version: $SDKMANAGER_VERSION"
else
echo -e "${RED}✗ Failed to add sdkmanager to PATH${NC}"
echo " Try running: source $SHELL_CONFIG"
exit 1
fi
else
echo ""
echo " Manual setup required:"
echo " 1. Add this line to $SHELL_CONFIG:"
echo " export PATH=\$PATH:\$ANDROID_HOME/cmdline-tools/latest/bin"
echo ""
echo " 2. Then run: source $SHELL_CONFIG"
exit 1
fi
fi
echo ""
# Check for Android build-tools and AAPT2
echo "9. Checking for Android build-tools and AAPT2..."
# Check if build-tools directory exists
if [ ! -d "$ANDROID_HOME/build-tools" ]; then
echo -e "${YELLOW}⚠ No build-tools directory found${NC}"
NEED_INSTALL=true
else
# Get the latest installed build-tools version by looking at directories
BUILD_TOOLS_VERSION=$(ls -1 "$ANDROID_HOME/build-tools" 2>/dev/null | grep -v "rc" | sort -V | tail -n 1)
if [ -z "$BUILD_TOOLS_VERSION" ]; then
echo -e "${YELLOW}⚠ No build-tools installed${NC}"
NEED_INSTALL=true
else
echo -e "${GREEN}✓ Build-tools installed: $BUILD_TOOLS_VERSION${NC}"
# Check if AAPT2 exists in the installed build-tools
AAPT2_PATH="$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION/aapt2"
APKSIGNER_PATH="$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION/apksigner"
echo ""
echo "10. Checking for AAPT2..."
if [ -f "$AAPT2_PATH" ]; then
echo -e "${GREEN}✓ AAPT2 found at: $AAPT2_PATH${NC}"
AAPT2_OK=true
else
echo -e "${YELLOW}⚠ AAPT2 not found at: $AAPT2_PATH${NC}"
AAPT2_OK=false
fi
echo ""
echo "11. Checking for apksigner..."
if [ -f "$APKSIGNER_PATH" ]; then
echo -e "${GREEN}✓ apksigner found at: $APKSIGNER_PATH${NC}"
APKSIGNER_OK=true
else
echo -e "${YELLOW}⚠ apksigner not found at: $APKSIGNER_PATH${NC}"
APKSIGNER_OK=false
fi
# Need to install if either tool is missing
if [ "$AAPT2_OK" = false ] || [ "$APKSIGNER_OK" = false ]; then
echo ""
echo " Build-tools may be corrupted or incomplete"
NEED_INSTALL=true
else
NEED_INSTALL=false
fi
fi
fi
if [ "$NEED_INSTALL" = true ]; then
echo ""
# Get the latest available build-tools version
LATEST_BUILD_TOOLS=$(sdkmanager --list 2>/dev/null | grep "build-tools;" | grep -v "rc" | head -n 1 | awk '{print $1}')
if [ -z "$LATEST_BUILD_TOOLS" ]; then
echo -e "${RED}✗ Could not determine latest build-tools version${NC}"
echo " Try running: sdkmanager --list"
exit 1
fi
echo " Latest available: $LATEST_BUILD_TOOLS"
echo ""
read -p " Install $LATEST_BUILD_TOOLS automatically? (y/N): " INSTALL_BUILD_TOOLS
if [ "$INSTALL_BUILD_TOOLS" = "y" ] || [ "$INSTALL_BUILD_TOOLS" = "Y" ]; then
echo ""
echo " Running the following commands:"
echo " yes | sdkmanager --licenses"
echo " sdkmanager \"$LATEST_BUILD_TOOLS\""
echo ""
echo " Installing $LATEST_BUILD_TOOLS..."
echo ""
# Accept licenses first
yes | sdkmanager --licenses >/dev/null 2>&1
# Install build-tools
sdkmanager "$LATEST_BUILD_TOOLS"
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Build-tools installed successfully${NC}"
# Verify AAPT2 and apksigner are now present
BUILD_TOOLS_VERSION=$(echo "$LATEST_BUILD_TOOLS" | sed 's/build-tools;//')
AAPT2_PATH="$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION/aapt2"
APKSIGNER_PATH="$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION/apksigner"
echo ""
if [ -f "$AAPT2_PATH" ]; then
echo -e "${GREEN}✓ AAPT2 verified at: $AAPT2_PATH${NC}"
else
echo -e "${YELLOW}⚠ AAPT2 not found after installation${NC}"
fi
if [ -f "$APKSIGNER_PATH" ]; then
echo -e "${GREEN}✓ apksigner verified at: $APKSIGNER_PATH${NC}"
else
echo -e "${YELLOW}⚠ apksigner not found after installation${NC}"
fi
else
echo -e "${RED}✗ Failed to install build-tools${NC}"
exit 1
fi
else
echo ""
echo " Manual installation required:"
echo " 1. Accept licenses: sdkmanager --licenses"
echo " 2. Install build-tools: sdkmanager \"$LATEST_BUILD_TOOLS\""
echo ""
read -p " Continue without build-tools? (y/N): " CONTINUE_WITHOUT_BUILD_TOOLS
if [ "$CONTINUE_WITHOUT_BUILD_TOOLS" != "y" ] && [ "$CONTINUE_WITHOUT_BUILD_TOOLS" != "Y" ]; then
exit 1
fi
fi
fi
echo ""
# Check if build-tools are in PATH for easier access to apksigner and other tools
echo "12. Checking if build-tools are in PATH..."
# Get the latest build-tools version
if [ -d "$ANDROID_HOME/build-tools" ]; then
BUILD_TOOLS_VERSION=$(ls -1 "$ANDROID_HOME/build-tools" 2>/dev/null | grep -v "rc" | sort -V | tail -n 1)
BUILD_TOOLS_BIN="$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION"
if command -v apksigner &> /dev/null; then
echo -e "${GREEN}✓ build-tools are in PATH${NC}"
echo " apksigner and other build tools are accessible"
else
echo -e "${YELLOW}⚠ build-tools are not in PATH${NC}"
echo " You can access apksigner at:"
echo " $BUILD_TOOLS_BIN/apksigner"
echo ""
# Detect shell
SHELL_CONFIG=""
if [ -n "$BASH_VERSION" ]; then
SHELL_CONFIG="$HOME/.bashrc"
elif [ -n "$ZSH_VERSION" ]; then
SHELL_CONFIG="$HOME/.zshrc"
else
case "$SHELL" in
*/bash)
SHELL_CONFIG="$HOME/.bashrc"
;;
*/zsh)
SHELL_CONFIG="$HOME/.zshrc"
;;
*)
SHELL_CONFIG="$HOME/.bashrc"
;;
esac
fi
read -p " Add build-tools to $SHELL_CONFIG automatically? (y/N): " ADD_BUILD_TOOLS_PATH
if [ "$ADD_BUILD_TOOLS_PATH" = "y" ] || [ "$ADD_BUILD_TOOLS_PATH" = "Y" ]; then
# Check if the export already exists in the file
if grep -q "ANDROID_HOME/build-tools" "$SHELL_CONFIG" 2>/dev/null; then
echo -e "${YELLOW} Build-tools path already exists in $SHELL_CONFIG${NC}"
else
echo "" >> "$SHELL_CONFIG"
echo "# Android build-tools" >> "$SHELL_CONFIG"
echo "export PATH=\$PATH:\$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION" >> "$SHELL_CONFIG"
echo -e "${GREEN}✓ Added to $SHELL_CONFIG${NC}"
fi
# Source the config file to apply changes immediately
echo ""
echo " Applying changes to current session..."
source "$SHELL_CONFIG"
# Verify apksigner is now accessible
if command -v apksigner &> /dev/null; then
echo -e "${GREEN}✓ apksigner is now in PATH${NC}"
else
echo -e "${RED}✗ Failed to add build-tools to PATH${NC}"
echo " Try running: source $SHELL_CONFIG"
fi
else
echo ""
echo -e "${YELLOW} To use apksigner and other build tools:${NC}"
echo " Option 1 - Add to PATH (recommended):"
echo " Add this line to $SHELL_CONFIG:"
echo " export PATH=\$PATH:\$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION"
echo " Then run: source $SHELL_CONFIG"
echo ""
echo " Option 2 - Use full path:"
echo " $BUILD_TOOLS_BIN/apksigner"
fi
fi
fi
echo ""
echo "=== Check Complete ==="
echo -e "${GREEN}All checks passed!${NC}"
# Exit with success if we got here
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment