Created
December 27, 2025 12:38
-
-
Save mvklingeren/0dcbdf111590c6ed8ddfb734e2eac68e to your computer and use it in GitHub Desktop.
Create a Android emulator by running ./setup_emulator.sh (it downloads google's commandline tools for this, and the Android image)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Store this file as setup_emulator.sh, then simpy execute it. | |
| # | |
| # | |
| # ============================================================================== | |
| # AUTO-SETUP: Android Emulator (Apple Silicon M-Series) | |
| # - Default: Android 16 (API 36) | |
| # - Preset: Pixel Tablet (2560x1600) | |
| # - Heap: 1GB | RAM: 4GB | |
| # ============================================================================== | |
| # --- DEFAULTS --- | |
| SDK_PATH="$HOME/android-sdk" | |
| CMD_TOOLS_URL="https://dl.google.com/android/repository/commandlinetools-mac-13114758_latest.zip" | |
| ZIP_NAME="commandlinetools-mac-13114758_latest.zip" | |
| AVD_NAME="M2_Pixel_Tablet" | |
| DEVICE_ID="pixel_tablet" # The Official Pixel Tablet Hardware Profile | |
| ANDROID_VER_NUM="36" # Android 16 | |
| # --- ARGUMENT PARSING --- | |
| ONLY_ADD_GAPPS=false | |
| for arg in "$@"; do | |
| case $arg in | |
| --setver=*) ANDROID_VER_NUM="${arg#*=}" ;; | |
| --add-gapps) ONLY_ADD_GAPPS=true ;; | |
| esac | |
| done | |
| ANDROID_IMAGE="system-images;android-${ANDROID_VER_NUM};google_apis_playstore;arm64-v8a" | |
| # --- HELPER: CONFIGURE AVD --- | |
| configure_avd_settings() { | |
| CONFIG_FILE="$HOME/.android/avd/$AVD_NAME.avd/config.ini" | |
| echo "βοΈ Patching AVD Configuration..." | |
| if [ ! -f "$CONFIG_FILE" ]; then | |
| echo "β Error: AVD config not found." | |
| exit 1 | |
| fi | |
| # Helper function | |
| set_config() { | |
| key=$1 | |
| val=$2 | |
| if grep -q "^$key" "$CONFIG_FILE"; then | |
| sed -i '' "s|^$key=.*|$key=$val|" "$CONFIG_FILE" | |
| else | |
| echo "$key=$val" >> "$CONFIG_FILE" | |
| fi | |
| } | |
| # --- 1. REMOVE BROKEN SKINS --- | |
| sed -i '' '/^skin.name/d' "$CONFIG_FILE" | |
| sed -i '' '/^skin.path/d' "$CONFIG_FILE" | |
| # --- 2. PIXEL TABLET SPECS --- | |
| echo "π₯οΈ Applying Pixel Tablet Specs (2560x1600)..." | |
| set_config "hw.lcd.width" "2560" | |
| set_config "hw.lcd.height" "1600" | |
| set_config "hw.lcd.density" "320" # Standard XHDPI for tablets | |
| set_config "hw.initialOrientation" "landscape" | |
| # --- 3. MEMORY SETTINGS --- | |
| echo "π§ Setting Memory: 1GB Heap / 4GB RAM..." | |
| set_config "vm.heapSize" "1024" # The requested 1GB Heap | |
| set_config "hw.ramSize" "4096" # System RAM (Needs 4GB for Android 16) | |
| # --- 4. KEYBOARD & HARDWARE --- | |
| set_config "hw.keyboard" "yes" | |
| set_config "hw.mainKeys" "yes" | |
| set_config "hw.trackBall" "no" | |
| set_config "hw.dPad" "no" | |
| # --- 5. GPU & PLAY STORE --- | |
| set_config "hw.gpu.mode" "auto" | |
| set_config "PlayStore.enabled" "true" | |
| set_config "tag.id" "google_apis_playstore" | |
| set_config "tag.display" "Google Play" | |
| echo "β Configuration Patched." | |
| } | |
| # --- MODE: JUST UPDATE CONFIG? --- | |
| if [ "$ONLY_ADD_GAPPS" = true ]; then | |
| configure_avd_settings | |
| exit 0 | |
| fi | |
| # ========================================================= | |
| # FULL INSTALLATION | |
| # ========================================================= | |
| echo "π Starting Setup (Android ${ANDROID_VER_NUM} - Pixel Tablet)..." | |
| # 1. Java Check | |
| if ! command -v java &> /dev/null; then | |
| echo "β Java JDK not found." | |
| exit 1 | |
| fi | |
| # 2. Download Tools | |
| mkdir -p "$SDK_PATH/cmdline-tools" | |
| if [ ! -d "$SDK_PATH/cmdline-tools/latest" ]; then | |
| if [ ! -f "$ZIP_NAME" ]; then | |
| echo "β¬οΈ Downloading Command Line Tools..." | |
| curl -o "$ZIP_NAME" "$CMD_TOOLS_URL" | |
| fi | |
| echo "π¦ Unzipping..." | |
| unzip -q "$ZIP_NAME" -d "$SDK_PATH/cmdline-tools" | |
| mv "$SDK_PATH/cmdline-tools/cmdline-tools" "$SDK_PATH/cmdline-tools/latest" | |
| fi | |
| export ANDROID_HOME="$SDK_PATH" | |
| export PATH="$SDK_PATH/cmdline-tools/latest/bin:$SDK_PATH/platform-tools:$SDK_PATH/emulator:$PATH" | |
| # 3. Install Image | |
| echo "β¬οΈ Downloading Android ${ANDROID_VER_NUM} Image..." | |
| yes | sdkmanager --licenses > /dev/null 2>&1 | |
| yes | sdkmanager "platform-tools" "emulator" "$ANDROID_IMAGE" | |
| # 4. Create Device | |
| echo "π± Creating Virtual Pixel Tablet..." | |
| avdmanager delete avd -n "$AVD_NAME" > /dev/null 2>&1 | |
| echo "no" | avdmanager create avd -n "$AVD_NAME" -k "$ANDROID_IMAGE" --device "$DEVICE_ID" --force | |
| # 5. Apply Config | |
| configure_avd_settings | |
| # 6. Create Launch Script | |
| cat <<EOT > ~/launch_android.sh | |
| #!/bin/bash | |
| export ANDROID_HOME="$SDK_PATH" | |
| export PATH="\$ANDROID_HOME/emulator:\$PATH" | |
| echo "π Launching Pixel Tablet (Android ${ANDROID_VER_NUM})..." | |
| $SDK_PATH/emulator/emulator -avd $AVD_NAME -gpu auto -accel on -skin 2560x1600 | |
| EOT | |
| chmod +x ~/launch_android.sh | |
| # 7. Create Desktop Shortcut (opens terminal) | |
| ln -sf ~/launch_android.sh ~/Desktop/Launch_Android.command | |
| echo "π₯οΈ Desktop shortcut created." | |
| # 8. Create .app in /Applications (no terminal), to easily launch the emulator from the Finder | |
| APP_PATH="/Applications/Android Emulator.app" | |
| rm -rf "$APP_PATH" | |
| mkdir -p "$APP_PATH/Contents/MacOS" | |
| cat <<'PLIST' > "$APP_PATH/Contents/Info.plist" | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>CFBundleExecutable</key> | |
| <string>launch</string> | |
| <key>CFBundleIdentifier</key> | |
| <string>com.android.emulator.launcher</string> | |
| <key>CFBundleName</key> | |
| <string>Android Emulator</string> | |
| <key>CFBundleVersion</key> | |
| <string>1.0</string> | |
| <key>LSUIElement</key> | |
| <true/> | |
| </dict> | |
| </plist> | |
| PLIST | |
| cat <<EOT > "$APP_PATH/Contents/MacOS/launch" | |
| #!/bin/bash | |
| export ANDROID_HOME="$SDK_PATH" | |
| export PATH="\$ANDROID_HOME/emulator:\$PATH" | |
| nohup $SDK_PATH/emulator/emulator -avd $AVD_NAME -gpu auto -accel on -skin 2560x1600 > /dev/null 2>&1 & | |
| EOT | |
| chmod +x "$APP_PATH/Contents/MacOS/launch" | |
| echo "π± App created: /Applications/Android Emulator.app" | |
| echo "----------------------------------------------------" | |
| echo "π SUCCESS! Pixel Tablet Ready." | |
| echo "Run: ~/launch_android.sh" | |
| echo "----------------------------------------------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment