|
1 | 1 | steps: |
| 2 | + - task: JavaToolInstaller@0 |
| 3 | + inputs: |
| 4 | + versionSpec: '17' |
| 5 | + jdkArchitectureOption: 'x64' |
| 6 | + jdkSourceOption: 'PreInstalled' |
2 | 7 | - task: Bash@3 |
3 | 8 | displayName: 'Android Emulator Setup' |
4 | 9 | inputs: |
5 | 10 | targetType: 'inline' |
6 | 11 | script: | |
7 | 12 | #!/usr/bin/env bash |
8 | | - set -ex |
| 13 | + set -eox pipefail |
9 | 14 |
|
10 | 15 | # Install AVD files |
11 | | - echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-27;default;x86_64' |
| 16 | + echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install 'system-images;android-30;google_apis;x86' |
12 | 17 |
|
13 | 18 | # Create emulator |
14 | | - echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n android_emulator -d 34 --package 'system-images;android-27;default;x86_64' |
| 19 | + echo "no" | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n android_emulator -k 'system-images;android-30;google_apis;x86' --force |
15 | 20 |
|
16 | | - # list emulator |
17 | | - echo "Available emulator" |
18 | 21 | $ANDROID_HOME/emulator/emulator -list-avds |
19 | 22 |
|
20 | | - if false; then |
21 | | - emulator_config=~/.android/avd/android_emulator.avd/config.ini |
22 | | - # The following is to support empty OR populated config.ini files, |
23 | | - # the state of which is dependant on the version of the emulator used (which we don't control), |
24 | | - # Replace existing config (NOTE we're on macOS so sed works differently!) |
25 | | - sed -i .bak 's/hw.lcd.density=.*/hw.lcd.density=420/' "$emulator_config" |
26 | | - sed -i .bak 's/hw.lcd.height=.*/hw.lcd.height=1920/' "$emulator_config" |
27 | | - sed -i .bak 's/hw.lcd.width=.*/hw.lcd.width=1080/' "$emulator_config" |
28 | | - # Or, add new config |
29 | | - if ! grep -q "hw.lcd.density" "$emulator_config"; then |
30 | | - echo "hw.lcd.density=420" >> "$emulator_config" |
31 | | - fi |
32 | | - if ! grep -q "hw.lcd.height" "$emulator_config"; then |
33 | | - echo "hw.lcd.height=1920" >> "$emulator_config" |
34 | | - fi |
35 | | - if ! grep -q "hw.lcd.width" "$emulator_config"; then |
36 | | - echo "hw.lcd.width=1080" >> "$emulator_config" |
37 | | - fi |
38 | | - echo "Emulator settings ($emulator_config)" |
39 | | - cat "$emulator_config" |
40 | | - fi |
41 | | -
|
42 | 23 | echo "Starting emulator" |
43 | 24 |
|
44 | 25 | # Start emulator in background |
45 | | - nohup $ANDROID_HOME/emulator/emulator -avd android_emulator -no-snapshot -no-audio -gpu host -no-boot-anim -qemu -m 2048 > /dev/null 2>&1 & |
| 26 | + nohup $ANDROID_HOME/emulator/emulator -avd android_emulator -no-snapshot -no-window -no-audio -no-boot-anim -accel off > /dev/null 2>&1 & |
46 | 27 | $ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82' |
47 | 28 |
|
48 | | - #list online device/emulator |
49 | 29 | $ANDROID_HOME/platform-tools/adb devices |
50 | 30 |
|
51 | 31 | echo "Emulator started" |
0 commit comments