Skip to content

Commit 9ce547d

Browse files
authored
Add example for installing/launching emulator to Android test doc (#47889)
1 parent 21ff47c commit 9ce547d

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

docs/workflow/testing/libraries/testing-android.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ unzip ~/andk.zip -d $(dirname ${ANDROID_NDK_ROOT}) && rm -rf ~/andk.zip
4242
# platform-tools, platforms and build-tools
4343
export ANDROID_SDK_ROOT=~/android-sdk
4444
curl https://dl.google.com/android/repository/commandlinetools-${HOST_OS_SHORT}-${SDK_VER}.zip -L --output ~/asdk.zip
45-
unzip ~/asdk.zip -d ${ANDROID_SDK_ROOT} && rm -rf ~/asdk.zip
46-
yes | ${ANDROID_SDK_ROOT}/tools/bin/./sdkmanager --sdk_root=${ANDROID_SDK_ROOT} --licenses
47-
${ANDROID_SDK_ROOT}/tools/bin/./sdkmanager --sdk_root=${ANDROID_SDK_ROOT} "platform-tools" "platforms;android-${SDK_API_LEVEL}" "build-tools;${SDK_BUILD_TOOLS}"
45+
mkdir ${ANDROID_SDK_ROOT} && unzip ~/asdk.zip -d ${ANDROID_SDK_ROOT}/cmdline-tools && rm -rf ~/asdk.zip
46+
yes | ${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} --licenses
47+
${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} "platform-tools" "platforms;android-${SDK_API_LEVEL}" "build-tools;${SDK_BUILD_TOOLS}"
4848

4949
# We also need to download precompiled binaries and headers for OpenSSL from maven, this step is a temporary hack
5050
# and will be removed once we figure out how to integrate OpenSSL properly as a dependency
@@ -65,7 +65,7 @@ and even run tests one by one for each library:
6565
```
6666
./build.sh libs.tests -os Android -arch x64 -test
6767
```
68-
Make sure an emulator is booted (see `AVD Manager`) or a device is plugged in and unlocked.
68+
Make sure an emulator is booted (see [`AVD Manager`](#avd-manager)) or a device is plugged in and unlocked.
6969
`AVD Manager` tool recommends to install `x86` images by default so if you follow that recommendation make sure `-arch x86` was used for the build script.
7070

7171
### Running individual test suites
@@ -85,6 +85,31 @@ adb logcat -s "DOTNET"
8585
```
8686
Or simply open `logcat` window in Android Studio or Visual Stuido.
8787

88+
### AVD Manager
89+
If Android Studio is installed, [AVD Manager](https://developer.android.com/studio/run/managing-avds) can be used from the IDE to create and start Android virtual devices. Otherwise, the Android SDK provides the [`avdmanager` command line tool](https://developer.android.com/studio/command-line/avdmanager).
90+
91+
Example of installing, creating, and launching emulators from the command line (where `SDK_API_LEVEL` matches the installed Android SDK and `EMULATOR_NAME_X86`/`EMULATOR_NAME_X64` are names of your choice):
92+
```bash
93+
# Install x86 image
94+
${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin/sdkmanager "system-images;android-${SDK_API_LEVEL};default;x86"
95+
96+
# Create x86 image
97+
${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin/avdmanager create avd --name ${EMULATOR_NAME_X86} --package "system-images;android-${SDK_API_LEVEL};default;x86"
98+
99+
# Launch emulator with x86 image
100+
${ANDROID_SDK_ROOT}/emulator/emulator -avd ${EMULATOR_NAME_X86} &
101+
102+
# Install x64 image
103+
${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin/sdkmanager "system-images;android-${SDK_API_LEVEL};default;x86_64"
104+
105+
# Create x64 image
106+
${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin/avdmanager create avd --name ${EMULATOR_NAME_X64} --package "system-images;android-${SDK_API_LEVEL};default;x86_64"
107+
108+
# Launch emulator with x64 image
109+
${ANDROID_SDK_ROOT}/emulator/emulator -avd ${EMULATOR_NAME_X64} &
110+
```
111+
The emulator can be launched with a variety of options. Run `emulator -help` to see the full list.
112+
88113
### Existing Limitations
89114
- `-os Android` is not supported for Windows yet (`WSL` can be used instead)
90115
- XHarness.CLI is not able to boot emulators yet (so you need to boot via `AVD Manager` or IDE)

0 commit comments

Comments
 (0)