-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement a bash script needed to configure simulators for App development #29061
Changes from all commits
b0afc32
b02536a
7c7c6cf
fc5cecb
2540bd8
0069124
51deb9d
75854f5
b2d504e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#!/bin/bash | ||
|
||
shubham1206agra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Utility script for iOS and Android Emulators | ||
# ============================================ | ||
# | ||
# Purpose: | ||
# -------- | ||
# This script helps to start and kill iOS simulators and Android emulators instances. | ||
# | ||
# How this script helps: | ||
# ---------------------- | ||
# This script streamlines the process of starting and killing on both android and ios | ||
# platforms. | ||
|
||
# Use functions and variables from the utils script | ||
source scripts/shellUtils.sh | ||
|
||
select_device_ios() | ||
{ | ||
# shellcheck disable=SC2124 | ||
IFS="$@" arr=$(xcrun xctrace list devices | grep -E "iPhone|iPad") | ||
|
||
# Create arrays to store device names and identifiers | ||
device_names=() | ||
device_identifiers=() | ||
|
||
# Parse the device list and populate the arrays | ||
while IFS= read -r line; do | ||
if [[ $line =~ ^(.*)\ \((.*)\)\ \((.*)\)$ ]]; then | ||
device="${BASH_REMATCH[1]}" | ||
version="${BASH_REMATCH[2]}" | ||
identifier="${BASH_REMATCH[3]}" | ||
device_identifiers+=("$identifier") | ||
device_names+=("$device Version: $version") | ||
else | ||
info "Input does not match the expected pattern." | ||
echo "$line" | ||
fi | ||
done <<< "$arr" | ||
if [ ${#device_names[@]} -eq 0 ]; then | ||
error "No devices detected, please create one." | ||
exit 1 | ||
fi | ||
if [ ${#device_names[@]} -eq 1 ]; then | ||
device_identifier="${device_identifiers[0]}" | ||
success "Single device detected, launching ${device_names[0]}" | ||
open -a Simulator --args -CurrentDeviceUDID "$device_identifier" | ||
return | ||
fi | ||
info "Multiple devices detected, please select one from the list." | ||
PS3='Please enter your choice: ' | ||
select device_name in "${device_names[@]}"; do | ||
if [ -n "$device_name" ]; then | ||
selected_index=$((REPLY - 1)) | ||
device_name_for_display="${device_names[$selected_index]}" | ||
device_identifier="${device_identifiers[$selected_index]}" | ||
break | ||
else | ||
echo "Invalid selection. Please choose a device." | ||
fi | ||
done | ||
success "Launching $device_name_for_display" | ||
open -a Simulator --args -CurrentDeviceUDID "$device_identifier" | ||
} | ||
|
||
kill_all_emulators_ios() { | ||
# kill all the emulators | ||
killall Simulator | ||
} | ||
|
||
restart_adb_server() { | ||
info "Restarting adb ..." | ||
adb kill-server | ||
sleep 2 | ||
adb start-server | ||
sleep 2 | ||
info "Restarting adb done" | ||
} | ||
|
||
ensure_device_available() { | ||
# Must turn off exit on error temporarily | ||
set +e | ||
if adb devices | grep -q offline; then | ||
restart_adb_server | ||
if adb devices | grep -q offline; then | ||
error "Device remains 'offline'. Please investigate!" | ||
exit 1 | ||
fi | ||
fi | ||
set -e | ||
} | ||
|
||
select_device_android() | ||
{ | ||
# shellcheck disable=SC2124 | ||
IFS="$@" arr=$(emulator -list-avds) | ||
|
||
# Create arrays to store device names | ||
device_names=() | ||
|
||
# Parse the device list and populate the arrays | ||
while IFS= read -r line; do | ||
device_names+=("$line") | ||
done <<< "$arr" | ||
if [ ${#device_names[@]} -eq 0 ]; then | ||
error "No devices detected, please create one." | ||
exit 1 | ||
fi | ||
if [ ${#device_names[@]} -eq 1 ]; then | ||
device_identifier="${device_names[0]}" | ||
success "Single device detected, launching $device_identifier" | ||
emulator -avd "$device_identifier" -writable-system > /dev/null 2>&1 & | ||
return | ||
fi | ||
info "Multiple devices detected, please select one from the list." | ||
PS3='Please enter your choice: ' | ||
select device_name in "${device_names[@]}"; do | ||
if [ -n "$device_name" ]; then | ||
selected_index=$((REPLY - 1)) | ||
device_identifier="${device_names[$selected_index]}" | ||
break | ||
else | ||
echo "Invalid selection. Please choose a device." | ||
fi | ||
done | ||
success "Launching $device_identifier" | ||
emulator -avd "$device_identifier" -writable-system > /dev/null 2>&1 & | ||
} | ||
|
||
kill_all_emulators_android() { | ||
# kill all the emulators | ||
adb devices | grep emulator | cut -f1 | while read -r line; do adb -s "$line" emu kill; done | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/bin/bash | ||
|
||
# NewDot Web Configuration Script for iOS and Android Emulators | ||
# ============================================================= | ||
# | ||
# Purpose: | ||
# -------- | ||
# This script configures Configure iOS simulators and Android emulators to connect to | ||
# new.expensify.com.dev over https for local development. | ||
# | ||
# Background: | ||
# ----------- | ||
# We plan to change the URL to serve the App on the development environment from | ||
# localhost:8082 to new.expensify.com.dev. This can be accomplished by adding a new entry | ||
# to the laptop's hosts file along with changes made in the PR. | ||
# However, we're not sure how we can access the App on Safari or Chrome on iOS or Android | ||
# simulators. | ||
# | ||
# How this script helps: | ||
# ---------------------- | ||
# This script streamlines the process of adding the certificates to both android and | ||
# ios platforms. | ||
# | ||
# Usage: | ||
# ------ | ||
# To run this script, pass the platform on which you want to run as a command-line | ||
# argument which can be the following: | ||
# 1. ios | ||
# 2. android | ||
# 3. all (default) | ||
# ./setup-newdot-web-emulators.sh platform | ||
|
||
# Use functions and variables from the utils script | ||
source scripts/shellUtils.sh | ||
|
||
# Use functions to select and open the emulator for iOS and Android | ||
source scripts/select-device.sh | ||
|
||
if [ $# -eq 0 ]; then | ||
platform="all" | ||
else | ||
platform=$1 | ||
fi | ||
|
||
setup_ios() | ||
{ | ||
select_device_ios | ||
sleep 30 | ||
info "Installing certificates on iOS simulator" | ||
xcrun simctl keychain booted add-root-cert "$(mkcert -CAROOT)/rootCA.pem" | ||
kill_all_emulators_ios | ||
} | ||
|
||
setup_android_path_1() | ||
{ | ||
adb root || { | ||
error "Failed to restart adb as root" | ||
info "You may want to check https://stackoverflow.com/a/45668555" | ||
exit 1 | ||
} | ||
sleep 2 | ||
adb remount | ||
adb push /etc/hosts /system/etc/hosts | ||
kill_all_emulators_android | ||
} | ||
|
||
setup_android_path_2() | ||
{ | ||
adb root || { | ||
error "Failed to restart adb as root" | ||
info "You may want to check https://stackoverflow.com/a/45668555" | ||
exit 1 | ||
} | ||
sleep 2 | ||
adb disable-verity | ||
adb reboot | ||
sleep 30 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how do we come up with these numbers like 2 seconds, 30 seconds? Is there a way to avoid so many There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope |
||
ensure_device_available | ||
adb root | ||
sleep 2 | ||
adb remount | ||
adb push /etc/hosts /system/etc/hosts | ||
kill_all_emulators_android | ||
} | ||
|
||
setup_android() | ||
{ | ||
select_device_android | ||
sleep 30 | ||
ensure_device_available | ||
info "Installing certificates on Android emulator" | ||
setup_android_path_1 || { | ||
info "Looks like the system partition is read-only" | ||
info "Trying another method to install the certificates" | ||
setup_android_path_2 | ||
} | ||
} | ||
|
||
if [ "$platform" = "ios" ] || [ "$platform" = "all" ]; then | ||
setup_ios || { | ||
error "Failed to setup iOS simulator" | ||
exit 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why exit if ios fails? especially if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So that the user knows immediately that the flow failed. Instead of thinking that the flow passed. |
||
} | ||
fi | ||
|
||
if [ "$platform" = "android" ] || [ "$platform" = "all" ]; then | ||
setup_android || { | ||
error "Failed to setup Android emulator" | ||
exit 1 | ||
} | ||
fi | ||
|
||
success "Done!" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
#!/bin/bash | ||
|
||
declare -r GREEN=$'\e[1;32m' | ||
declare -r RED=$'\e[1;31m' | ||
declare -r BLUE=$'\e[1;34m' | ||
declare -r TITLE=$'\e[1;4;34m' | ||
declare -r RESET=$'\e[0m' | ||
# Check if GREEN has already been defined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need to change this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cause this is causing errors |
||
if [ -z "${GREEN+x}" ]; then | ||
declare -r GREEN=$'\e[1;32m' | ||
fi | ||
|
||
# Check if RED has already been defined | ||
if [ -z "${RED+x}" ]; then | ||
declare -r RED=$'\e[1;31m' | ||
fi | ||
|
||
# Check if BLUE has already been defined | ||
if [ -z "${BLUE+x}" ]; then | ||
declare -r BLUE=$'\e[1;34m' | ||
fi | ||
|
||
# Check if TITLE has already been defined | ||
if [ -z "${TITLE+x}" ]; then | ||
declare -r TITLE=$'\e[1;4;34m' | ||
fi | ||
|
||
# Check if RESET has already been defined | ||
if [ -z "${RESET+x}" ]; then | ||
declare -r RESET=$'\e[0m' | ||
fi | ||
|
||
function success { | ||
echo "🎉 $GREEN$1$RESET" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
# Script for starting android emulator correctly | ||
|
||
# Use functions to select and open the emulator for iOS and Android | ||
source scripts/select-device.sh | ||
|
||
select_device_android | ||
sleep 30 | ||
ensure_device_available | ||
adb reverse tcp:8082 tcp:8082 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these supposed to be a part of prebuild? or atleast added to the README? @hayata-suenaga ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think README.md will be updated here
#28422
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shubham1206agra can you check the current README change in that PR and put a comment in that PR on additional instruction we need to add because of these new scripts if there are any?