Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cmccarthyIrl committed Mar 9, 2024
1 parent eb5d6f6 commit 065e6d7
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions .github/scripts/startEmulator.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

# Set up Android SDK environment variables
export ANDROID_HOME=/usr/local/lib/android/sdk
ANDROID_HOME=~/usr/local/lib/android/sdk
export PATH=$ANDROID_HOME/emulator/:$PATH
export PATH=$ANDROID_HOME/platform-tools/:$PATH
export PATH=$ANDROID_HOME/cmdline-tools/latest/bin/:$PATH
Expand All @@ -23,33 +22,19 @@ fi
# Add adb directory to PATH
export PATH="$(dirname $ADB):$PATH"

# Function to check if a package is installed and install it if missing
check_and_install_package() {
if ! command -v "$1" &>/dev/null; then
echo "$1 is not installed. Installing it now..."
"$ANDROID_HOME"/cmdline-tools/latest/bin/sdkmanager --install "$2" --verbose
fi
}

# Check and install required packages
check_and_install_package "sdkmanager" "platform-tools"
check_and_install_package "avdmanager" "system-images;android-31;default;x86_64"
check_and_install_package "emulator" "emulator"
echo "Start the ADB server"
$ADB start-server

# Start the ADB server
adb start-server

# Create AVD
echo "Creating AVD..."
echo "no" | avdmanager -v create avd \
echo "Create AVD..."
echo "no" | "$ANDROID_HOME"/cmdline-tools/latest/bin/avdmanager -v create avd \
-n testRunnner \
-k "system-images;android-31;default;x86_64" \
-f \
--force
echo "Emulators:"
"$ANDROID_HOME"/emulator/emulator -list-avds

# Start emulator
echo "Starting emulator..."
nohup emulator -avd testRunnner \
nohup "$ANDROID_HOME"/emulator/emulator -avd testRunnner \
-skin 1080x1920 \
-no-snapshot \
-no-audio \
Expand All @@ -61,17 +46,22 @@ nohup emulator -avd testRunnner \
# Wait for the emulator to fully boot
tries=0
while [ $tries -lt 20 ]; do
if adb devices | grep -q emulator; then
if $ADB devices | grep -q emulator; then
break
fi
echo "Waiting for emulator to be detected..."
sleep 10
tries=$((tries + 1))
done

if ! adb devices | grep -q emulator; then
if ! $ADB devices | grep -q emulator; then
echo "Emulator not detected after multiple attempts. Exiting."
exit 1
fi

echo "Emulator started successfully."
# Additional sleep for stability
sleep 10

echo "Connected Devices:"
$ADB devices
echo "Emulator started"

0 comments on commit 065e6d7

Please sign in to comment.