Skip to content

Commit

Permalink
Merge pull request #2 from mrmike/support-wipe-option
Browse files Browse the repository at this point in the history
Supports --wipe option
  • Loading branch information
mrmike authored Jan 3, 2022
2 parents e18ab87 + 2f354aa commit d626797
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ By default script will look on emulators located at `~/.android/avd`. Script acc
./fix-android-emulator-audio path/to/your/avd/directory
```

Optionally you can pass `--wipe` option to wipe emulator's data so you don't have to do it manually via Android Studio. Script removes following files and directories:
```
* snapshots/
* userdata.img
* userdata-qemu.img
```

When running emulator for the first time after applying the fix make sure that data is wiped and emulator is started with Cold Boot option.
<p align="center">
<img width="449" alt="coldboot" src="https://user-images.githubusercontent.com/529635/146804992-07182ed9-b195-4b0a-90fe-6adc3c79f2ec.png">
Expand Down
28 changes: 27 additions & 1 deletion fix-android-emulator-audio
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,27 @@ function run_sed {
fi
}

# Check the number of arguments
if [ "$#" -gt 2 ]; then
echo "❌ Too many arguments."
echo "Usage: $0 <avd-path>"
exit 1
fi

temp_avd_path=""
has_wipe_option=0
# Read user arguments
for arg in "$@"
do
if [ $arg == "--wipe" ]; then
has_wipe_option=1
else
temp_avd_path=$arg
fi
done

# Use provided path by user or fallback to the default one
avd_path=${1:-$DEFAULT_AVD_PATH}
avd_path=${temp_avd_path:-$DEFAULT_AVD_PATH}
# Remove trailing slash if present
avd_path=${avd_path%/}
echo "🔊 Processing emulators from: $avd_path"
Expand All @@ -37,5 +56,12 @@ for emulator in $(find $avd_path -type d -name '*.avd'); do
# Sort config keys
sort -o $emulator/config.ini $emulator/config.ini

# Wipe data when --wipe argument is present
if [ $has_wipe_option -eq 1 ]; then
echo "🗑️ Wiping data from: $(basename $emulator)"
rm -rf $emulator/snapshots
rm -f $emulator/userdata.img $emulator/userdata-qemu.img
fi

echo "✅ Done - $(basename $emulator)"
done

0 comments on commit d626797

Please sign in to comment.