Skip to content

Commit b0f3c52

Browse files
committed
Support specifying SD card path or size.
1 parent 308aa23 commit b0f3c52

File tree

8 files changed

+32
-20
lines changed

8 files changed

+32
-20
lines changed

.github/workflows/workflow.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ jobs:
6868
target: ${{ matrix.target }}
6969
arch: x86
7070
profile: Nexus 6
71+
sdcard-path-or-size: 100M
7172
avd-name: test
7273
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -camera-back none
7374
disable-animations: true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ jobs:
9292
| `target` | Optional | `default` | Target of the system image - `default`, `google_apis` or `playstore`. |
9393
| `arch` | Optional | `x86` | CPU architecture of the system image - `x86` or `x86_64`. Note that `x86_64` image is only available for API 21+. |
9494
| `profile` | Optional | N/A | Hardware profile used for creating the AVD - e.g. `Nexus 6`. For a list of all profiles available, run `avdmanager list` and refer to the results under "Available Android Virtual Devices". |
95+
| `sdcard-path-or-size` | Optional | N/A | Path to the SD card image for this AVD or the size of a new SD card image to create for this AVD, in KB or MB, denoted with K or M. - e.g. `path/to/sdcard`, or `1000M`. |
9596
| `avd-name` | Optional | `test` | Custom AVD name used for creating the Android Virtual Device. |
9697
| `emulator-options` | Optional | See below | Command-line options used when launching the emulator (replacing all default options) - e.g. `-no-window -no-snapshot -camera-back emulated`. |
9798
| `disable-animations` | Optional | `true` | Whether to disable animations - `true` or `false`. |

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ inputs:
1616
default: 'x86'
1717
profile:
1818
description: 'hardware profile used for creating the AVD - e.g. `Nexus 6`'
19+
sdcard-path-or-size:
20+
description: 'path to the SD card image for this AVD or the size of a new SD card image to create for this AVD, in KB or MB, denoted with K or M. - e.g. `path/to/sdcard`, or `1000M`'
1921
avd-name:
2022
description: 'custom AVD name used for creating the Android Virtual Device'
2123
default: 'test'

lib/emulator-manager.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,13 @@ const EMULATOR_BOOT_TIMEOUT_SECONDS = 600;
3434
/**
3535
* Creates and launches a new AVD instance with the specified configurations.
3636
*/
37-
function launchEmulator(apiLevel, target, arch, profile, avdName, emulatorOptions, disableAnimations) {
37+
function launchEmulator(apiLevel, target, arch, profile, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations) {
3838
return __awaiter(this, void 0, void 0, function* () {
3939
// create a new AVD
40-
if (profile.trim() !== '') {
41-
console.log(`Creating AVD with custom profile ${profile}`);
42-
yield exec.exec(`avdmanager create avd --force -n "${avdName}" --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`);
43-
}
44-
else {
45-
console.log(`Creating AVD without custom profile.`);
46-
yield exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n "${avdName}" --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`);
47-
}
40+
const profileOption = profile.trim() !== '' ? `--device "${profile}"` : '';
41+
const sdcardPathOrSizeOption = sdcardPathOrSize.trim() !== '' ? `--sdcard "${sdcardPathOrSize}"` : '';
42+
console.log(`Creating AVD.`);
43+
yield exec.exec(`avdmanager create avd --force -n "${avdName}" --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" ${profileOption} ${sdcardPathOrSizeOption}`);
4844
// start emulator
4945
console.log('Starting emulator.');
5046
// turn off hardware acceleration on Linux

lib/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ function run() {
6363
// Hardware profile used for creating the AVD
6464
const profile = core.getInput('profile');
6565
console.log(`Hardware profile: ${profile}`);
66+
// SD card path or size used for creating the AVD
67+
const sdcardPathOrSize = core.getInput('sdcard-path-or-size');
68+
console.log(`SD card path or size: ${sdcardPathOrSize}`);
6669
// custom name used for creating the AVD
6770
const avdName = core.getInput('avd-name');
6871
console.log(`AVD name: ${avdName}`);
@@ -109,7 +112,7 @@ function run() {
109112
// install SDK
110113
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, emulatorBuild, ndkVersion, cmakeVersion);
111114
// launch an emulator
112-
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, avdName, emulatorOptions, disableAnimations);
115+
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations);
113116
// execute the custom script
114117
try {
115118
// move to custom working directory if set

src/emulator-manager.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@ const EMULATOR_BOOT_TIMEOUT_SECONDS = 600;
55
/**
66
* Creates and launches a new AVD instance with the specified configurations.
77
*/
8-
export async function launchEmulator(apiLevel: number, target: string, arch: string, profile: string, avdName: string, emulatorOptions: string, disableAnimations: boolean): Promise<void> {
8+
export async function launchEmulator(
9+
apiLevel: number,
10+
target: string,
11+
arch: string,
12+
profile: string,
13+
sdcardPathOrSize: string,
14+
avdName: string,
15+
emulatorOptions: string,
16+
disableAnimations: boolean
17+
): Promise<void> {
918
// create a new AVD
10-
if (profile.trim() !== '') {
11-
console.log(`Creating AVD with custom profile ${profile}`);
12-
await exec.exec(`avdmanager create avd --force -n "${avdName}" --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`);
13-
} else {
14-
console.log(`Creating AVD without custom profile.`);
15-
await exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n "${avdName}" --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`);
16-
}
19+
const profileOption = profile.trim() !== '' ? `--device "${profile}"` : '';
20+
const sdcardPathOrSizeOption = sdcardPathOrSize.trim() !== '' ? `--sdcard "${sdcardPathOrSize}"` : '';
21+
console.log(`Creating AVD.`);
22+
await exec.exec(`avdmanager create avd --force -n "${avdName}" --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" ${profileOption} ${sdcardPathOrSizeOption}`);
1723

1824
// start emulator
1925
console.log('Starting emulator.');

src/main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ async function run() {
3939
const profile = core.getInput('profile');
4040
console.log(`Hardware profile: ${profile}`);
4141

42+
// SD card path or size used for creating the AVD
43+
const sdcardPathOrSize = core.getInput('sdcard-path-or-size');
44+
console.log(`SD card path or size: ${sdcardPathOrSize}`);
45+
4246
// custom name used for creating the AVD
4347
const avdName = core.getInput('avd-name');
4448
console.log(`AVD name: ${avdName}`);
@@ -94,7 +98,7 @@ async function run() {
9498
await installAndroidSdk(apiLevel, target, arch, emulatorBuild, ndkVersion, cmakeVersion);
9599

96100
// launch an emulator
97-
await launchEmulator(apiLevel, target, arch, profile, avdName, emulatorOptions, disableAnimations);
101+
await launchEmulator(apiLevel, target, arch, profile, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations);
98102

99103
// execute the custom script
100104
try {

test-fixture/app/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
3-
apply plugin: 'kotlin-android-extensions'
43

54
android {
65
compileSdkVersion 30

0 commit comments

Comments
 (0)