-
Notifications
You must be signed in to change notification settings - Fork 1.4k
chore: update script to create android emulator #7006
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
Open
Rohit3523
wants to merge
7
commits into
develop
Choose a base branch
from
android-script-fix
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
21d2df8
update script
Rohit3523 6412bd0
remove command
Rohit3523 e0bc963
Merge branch 'develop' into android-script-fix
Rohit3523 00b41ea
fix
Rohit3523 7a0a16e
Merge branch 'android-script-fix' of https://github.com/RocketChat/Ro…
Rohit3523 700bf4d
fix
Rohit3523 b6c5294
use script to config emulator
Rohit3523 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,76 @@ | ||
| #!/usr/bin/env bash | ||
| set -e | ||
|
|
||
| $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install emulator | ||
| if [ -z "$ANDROID_HOME" ]; then | ||
| export ANDROID_HOME="$ANDROID_SDK_ROOT" | ||
| fi | ||
|
|
||
| $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "system-images;android-31;default;arm64-v8a" | ||
| $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses | ||
| if [ -z "$ANDROID_HOME" ]; then | ||
| export ANDROID_HOME="$HOME/Android/Sdk" | ||
| fi | ||
|
|
||
| $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n Pixel_API_31_AOSP -d pixel --package "system-images;android-31;default;arm64-v8a" | ||
| export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH | ||
|
|
||
| echo "hw.lcd.density = 440" >> ~/.android/avd/Pixel_API_31_AOSP.avd/config.ini | ||
| echo "hw.lcd.height = 2280" >> ~/.android/avd/Pixel_API_31_AOSP.avd/config.ini | ||
| echo "hw.lcd.width = 1080" >> ~/.android/avd/Pixel_API_31_AOSP.avd/config.ini | ||
| API_LEVEL=34 | ||
| PROFILE="pixel_7_pro" | ||
| TARGET="google_apis" | ||
|
|
||
| echo "Pixel_API_31_AOSP created" | ||
| HOST_ARCH=$(uname -m) | ||
|
|
||
| if [[ "$HOST_ARCH" == "arm64" || "$HOST_ARCH" == "aarch64" ]]; then | ||
| ABI="arm64-v8a" | ||
| else | ||
| ABI="x86_64" | ||
| fi | ||
|
|
||
| AVD_NAME="${PROFILE}-api-${API_LEVEL}-${TARGET}-${ABI}" | ||
|
|
||
| export API_LEVEL | ||
| export PROFILE | ||
| export TARGET | ||
| export ABI | ||
| export AVD_NAME | ||
|
|
||
| if [ -n "$GITHUB_ENV" ]; then | ||
| echo "API_LEVEL=$API_LEVEL" >> "$GITHUB_ENV" | ||
| echo "PROFILE=$PROFILE" >> "$GITHUB_ENV" | ||
| echo "TARGET=$TARGET" >> "$GITHUB_ENV" | ||
| echo "ABI=$ABI" >> "$GITHUB_ENV" | ||
| echo "AVD_NAME=$AVD_NAME" >> "$GITHUB_ENV" | ||
| fi | ||
|
|
||
| # ✅ STOP HERE when running in GitHub Actions | ||
| if [ "$GITHUB_ACTIONS" = "true" ]; then | ||
| echo "Running in GitHub Actions — skipping AVD creation" | ||
| exit 0 | ||
| fi | ||
|
|
||
| HOST_ARCH=$(uname -m) | ||
| echo "Host architecture: $HOST_ARCH" | ||
| echo "Using emulator ABI: $ABI" | ||
|
|
||
| IMAGE="system-images;android-${API_LEVEL};${TARGET};${ABI}" | ||
|
|
||
| echo "Installing emulator + system image" | ||
|
|
||
| sdkmanager --install emulator | ||
| sdkmanager "$IMAGE" | ||
| yes | sdkmanager --licenses | ||
|
|
||
| echo "Creating AVD" | ||
|
|
||
| echo "no" | avdmanager create avd \ | ||
| -n "$AVD_NAME" \ | ||
| -d "$PROFILE" \ | ||
| --package "$IMAGE" | ||
|
|
||
| CONFIG="$HOME/.android/avd/${AVD_NAME}.avd/config.ini" | ||
|
|
||
| echo "hw.lcd.density=440" >> "$CONFIG" | ||
| echo "hw.lcd.height=2280" >> "$CONFIG" | ||
| echo "hw.lcd.width=1080" >> "$CONFIG" | ||
| echo "hw.gpu.enabled=yes" >> "$CONFIG" | ||
| echo "hw.ramSize=4096" >> "$CONFIG" | ||
| echo "vm.heapSize=512" >> "$CONFIG" | ||
|
|
||
| echo "AVD created: $AVD_NAME ($ABI)" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: RocketChat/Rocket.Chat.ReactNative
Length of output: 2338
🏁 Script executed:
Repository: RocketChat/Rocket.Chat.ReactNative
Length of output: 120
🌐 Web query:
avdmanager create avd --force idempotent options💡 Result:
To make
avdmanager create avdidempotent in scripts/CI, you basically have two choices:1) “Ensure this AVD exists (and matches my desired config)” → overwrite deterministically
Use force overwrite plus non-interactive input:
-f/--forceoverwrites an existing AVD with the same name (this is the closest built-in “idempotent” behavior). [1]echo "no" | ...avoids the interactive prompt (commonly used in CI). [2]Useful
create avdoptions (the ones that matter for reproducibility):-n/--nameAVD name (required) [1]-k/--packagesystem image package id (required) [1]-c/--sdcard {path|size}set/allocate SD card [1]-p/--pathAVD directory location [1]-f/--forceoverwrite existing AVD [1]--device,--tag,--abidepending on cmdline-tools version; these show up inavdmanager create avd --helpoutput in the field. [2]2) “Create only if missing” → don’t touch existing AVDs
Do an existence check first, then create without
--force:avdmanageritself doesn’t provide a dedicated “create-if-not-exists” flag; scripting withlist avdis the typical approach. [1]🏁 Script executed:
Repository: RocketChat/Rocket.Chat.ReactNative
Length of output: 106
🏁 Script executed:
Repository: RocketChat/Rocket.Chat.ReactNative
Length of output: 60
🏁 Script executed:
Repository: RocketChat/Rocket.Chat.ReactNative
Length of output: 287
🏁 Script executed:
Repository: RocketChat/Rocket.Chat.ReactNative
Length of output: 287
🌐 Web query:
avdmanager list avd output format "Name:" example💡 Result:
avdmanager list avdprints a “pretty” multi-line block per AVD that includes lines likeName:(and usuallyDevice:,Path:,Target:, etc.). Example output:[2]
If you need a script-friendly format,
avdmanagersupportslist ... -cfor “compact output suitable for scripts” when listing AVDs. [1]Sources: [1] https://developer.android.com/tools/avdmanager, [2] https://blog.csdn.net/wizardforcel/article/details/141383947
Add idempotency check or use
--forceflag to handle existing AVDs on reruns.Line 62 will fail on subsequent runs if the AVD already exists (
set -eaborts the script). Additionally, appending toconfig.ini(lines 67–74) will duplicate settings on reruns.Use
--forceflag for simpler idempotent creation:Suggested fix (simplest)
echo "no" | avdmanager create avd \ -n "$AVD_NAME" \ -d "$PROFILE" \ --package "$IMAGE" \ + --forceAlternatively, check and delete the existing AVD first (note: adjust the grep pattern—
avdmanager list avdoutput has leading whitespace beforeName:):Alternative: delete-then-create approach
🤖 Prompt for AI Agents