diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 5e6bb0c0..f954a6ab 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -52,6 +52,7 @@ jobs: target: default arch: x86 profile: Nexus 6 + avd-name: test emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -camera-back none disable-animations: true working-directory: ./test-fixture/ diff --git a/README.md b/README.md index 77e85b83..529568a0 100644 --- a/README.md +++ b/README.md @@ -88,12 +88,15 @@ jobs: ## Configurations +| | **Required** | **Default** | **Description** | +|----------------------|--------------|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | | **Required** | **Default** | **Description** | |----------------------|--------------|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `api-level` | Required | N/A | API level of the platform system image - e.g. 23 for Android Marshmallow, 29 for Android 10. **Minimum API level supported is 15**. | | `target` | Optional | `default` | Target of the system image - `default` or `google_apis`. | | `arch` | Optional | `x86` | CPU architecture of the system image - `x86` or `x86_64`. Note that `x86_64` image is only available for API 21+. | | `profile` | Optional | N/A | Hardware profile used for creating the AVD - e.g. `Nexus 6`. For a list of all profiles available, run `$ANDROID_HOME/tools/bin/avdmanager list` and refer to the results under "Available Android Virtual Devices". | +| `avd-name` | Optional | `test` | Custom AVD name used for creating the Android Virtual Device. | | `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`. | | `disable-animations` | Optional | `true` | Whether to disable animations - `true` or `false`. | | `emulator-build` | Optional | N/A | Build number of a specific version of the emulator binary to use e.g. `6061023` for emulator v29.3.0.0. | diff --git a/action.yml b/action.yml index 6d8976d8..0d4f0ea7 100644 --- a/action.yml +++ b/action.yml @@ -15,17 +15,20 @@ inputs: description: 'CPU architecture of the system image - x86 or x86_64' default: 'x86' profile: - description: 'hardware profile used for creating the AVD - e.g. `Nexus 6`.' + description: 'hardware profile used for creating the AVD - e.g. `Nexus 6`' + avd-name: + description: 'custom AVD name used for creating the Android Virtual Device' + default: 'test' emulator-options: - description: 'command-line options used when launching the emulator - e.g. `-no-window -no-snapshot -camera-back emulated`.' + description: 'command-line options used when launching the emulator - e.g. `-no-window -no-snapshot -camera-back emulated`' default: '-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim' disable-animations: description: 'whether to disable animations - true or false' default: 'true' emulator-build: - description: 'build number of a specific version of the emulator binary to use - e.g. `6061023` for emulator v29.3.0.0.' + description: 'build number of a specific version of the emulator binary to use - e.g. `6061023` for emulator v29.3.0.0' working-directory: - description: 'A custom working directory - e.g. `./android` if your root Gradle project is under the `./android` sub-directory within your repository.' + description: 'A custom working directory - e.g. `./android` if your root Gradle project is under the `./android` sub-directory within your repository' ndk: description: 'version of NDK to install - e.g. 21.0.6113669' cmake: diff --git a/lib/emulator-manager.js b/lib/emulator-manager.js index c8c788d1..ace29a7e 100644 --- a/lib/emulator-manager.js +++ b/lib/emulator-manager.js @@ -20,16 +20,16 @@ const EMULATOR_BOOT_TIMEOUT_SECONDS = 600; /** * Creates and launches a new AVD instance with the specified configurations. */ -function launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations) { +function launchEmulator(apiLevel, target, arch, profile, avdName, emulatorOptions, disableAnimations) { return __awaiter(this, void 0, void 0, function* () { // create a new AVD if (profile.trim() !== '') { console.log(`Creating AVD with custom profile ${profile}`); - yield exec.exec(`avdmanager create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`); + yield exec.exec(`avdmanager create avd --force -n "${avdName}" --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`); } else { console.log(`Creating AVD without custom profile.`); - yield exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n test --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`); + yield exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n "${avdName}" --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`); } // start emulator console.log('Starting emulator.'); @@ -37,7 +37,7 @@ function launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disabl if (process.platform === 'linux') { emulatorOptions += ' -accel off'; } - yield exec.exec(`sh -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd test ${emulatorOptions} &"`, [], { + yield exec.exec(`sh -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd "${avdName}" ${emulatorOptions} &"`, [], { listeners: { stderr: (data) => { if (data.toString().includes('invalid command-line parameter')) { diff --git a/lib/main.js b/lib/main.js index 367f7e43..f77d583a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,6 +49,9 @@ function run() { // Hardware profile used for creating the AVD const profile = core.getInput('profile'); console.log(`Hardware profile: ${profile}`); + // custom name used for creating the AVD + const avdName = core.getInput('avd-name'); + console.log(`AVD name: ${avdName}`); // emulator options const emulatorOptions = core.getInput('emulator-options').trim(); console.log(`emulator options: ${emulatorOptions}`); @@ -92,7 +95,7 @@ function run() { // install SDK yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, emulatorBuild, ndkVersion, cmakeVersion); // launch an emulator - yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations); + yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, avdName, emulatorOptions, disableAnimations); // execute the custom script try { // move to custom working directory if set diff --git a/src/emulator-manager.ts b/src/emulator-manager.ts index 03ebe502..2c40c010 100644 --- a/src/emulator-manager.ts +++ b/src/emulator-manager.ts @@ -5,14 +5,14 @@ const EMULATOR_BOOT_TIMEOUT_SECONDS = 600; /** * Creates and launches a new AVD instance with the specified configurations. */ -export async function launchEmulator(apiLevel: number, target: string, arch: string, profile: string, emulatorOptions: string, disableAnimations: boolean): Promise { +export async function launchEmulator(apiLevel: number, target: string, arch: string, profile: string, avdName: string, emulatorOptions: string, disableAnimations: boolean): Promise { // create a new AVD if (profile.trim() !== '') { console.log(`Creating AVD with custom profile ${profile}`); - await exec.exec(`avdmanager create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`); + await exec.exec(`avdmanager create avd --force -n "${avdName}" --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`); } else { console.log(`Creating AVD without custom profile.`); - await exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n test --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`); + await exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n "${avdName}" --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`); } // start emulator @@ -23,7 +23,7 @@ export async function launchEmulator(apiLevel: number, target: string, arch: str emulatorOptions += ' -accel off'; } - await exec.exec(`sh -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd test ${emulatorOptions} &"`, [], { + await exec.exec(`sh -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd "${avdName}" ${emulatorOptions} &"`, [], { listeners: { stderr: (data: Buffer) => { if (data.toString().includes('invalid command-line parameter')) { diff --git a/src/main.ts b/src/main.ts index 721f315f..4bc73b29 100644 --- a/src/main.ts +++ b/src/main.ts @@ -38,6 +38,10 @@ async function run() { const profile = core.getInput('profile'); console.log(`Hardware profile: ${profile}`); + // custom name used for creating the AVD + const avdName = core.getInput('avd-name'); + console.log(`AVD name: ${avdName}`); + // emulator options const emulatorOptions = core.getInput('emulator-options').trim(); console.log(`emulator options: ${emulatorOptions}`); @@ -89,7 +93,7 @@ async function run() { await installAndroidSdk(apiLevel, target, arch, emulatorBuild, ndkVersion, cmakeVersion); // launch an emulator - await launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations); + await launchEmulator(apiLevel, target, arch, profile, avdName, emulatorOptions, disableAnimations); // execute the custom script try {