From 1b2f005cf2cb5b87f19186af9c535f6c56154c50 Mon Sep 17 00:00:00 2001 From: munrocket Date: Tue, 24 Jun 2025 22:35:13 +0400 Subject: [PATCH 1/3] fix pre-launch-script --- src/emulator-manager.ts | 32 +++++++++++++++++++++++--------- src/main.ts | 28 +++++++++++++++++----------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/emulator-manager.ts b/src/emulator-manager.ts index 44633319a..9f5d69aa0 100644 --- a/src/emulator-manager.ts +++ b/src/emulator-manager.ts @@ -2,9 +2,9 @@ import * as exec from '@actions/exec'; import * as fs from 'fs'; /** - * Creates and launches a new AVD instance with the specified configurations. + * Creates a new AVD instance with the specified configurations. */ -export async function launchEmulator( +export async function createAvd( systemImageApiLevel: string, target: string, arch: string, @@ -16,16 +16,10 @@ export async function launchEmulator( diskSize: string, avdName: string, forceAvdCreation: boolean, - emulatorBootTimeout: number, - port: number, - emulatorOptions: string, - disableAnimations: boolean, - disableSpellChecker: boolean, - disableLinuxHardwareAcceleration: boolean, enableHardwareKeyboard: boolean ): Promise { try { - console.log(`::group::Launch Emulator`); + console.log(`::group::Create AVD`); // create a new AVD if AVD directory does not already exist or forceAvdCreation is true const avdPath = `${process.env.ANDROID_AVD_HOME}/${avdName}.avd`; if (!fs.existsSync(avdPath) || forceAvdCreation) { @@ -61,6 +55,26 @@ export async function launchEmulator( await exec.exec(`sh -c \\"printf '${configContent}' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini"`); } } + } finally { + console.log(`::endgroup::`); + } +} + +/** + * Launches an existing AVD instance with the specified configurations. + */ +export async function launchEmulator( + avdName: string, + emulatorBootTimeout: number, + port: number, + emulatorOptions: string, + disableAnimations: boolean, + disableSpellChecker: boolean, + disableLinuxHardwareAcceleration: boolean, + enableHardwareKeyboard: boolean +): Promise { + try { + console.log(`::group::Launch Emulator`); // turn off hardware acceleration on Linux if (process.platform === 'linux' && disableLinuxHardwareAcceleration) { diff --git a/src/main.ts b/src/main.ts index 096f00aa4..e144665d6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -14,7 +14,7 @@ import { checkPort, MIN_PORT, } from './input-validator'; -import { launchEmulator, killEmulator } from './emulator-manager'; +import { createAvd, launchEmulator, killEmulator } from './emulator-manager'; import * as exec from '@actions/exec'; import { parseScript } from './script-parser'; import { getChannelId } from './channel-id-mapper'; @@ -191,6 +191,22 @@ async function run() { // install SDK await installAndroidSdk(apiLevel, systemImageApiLevel, target, arch, channelId, emulatorBuild, ndkVersion, cmakeVersion); + // create AVD + await createAvd( + systemImageApiLevel, + target, + arch, + profile, + cores, + ramSize, + heapSize, + sdcardPathOrSize, + diskSize, + avdName, + forceAvdCreation, + enableHardwareKeyboard + ); + // execute pre emulator launch script if set if (preEmulatorLaunchScripts !== undefined) { console.log(`::group::Run pre emulator launch script`); @@ -210,17 +226,7 @@ async function run() { // launch an emulator await launchEmulator( - systemImageApiLevel, - target, - arch, - profile, - cores, - ramSize, - heapSize, - sdcardPathOrSize, - diskSize, avdName, - forceAvdCreation, emulatorBootTimeout, port, emulatorOptions, From fdee0abc94edaa349aa72647910dbefa2ba5ceb2 Mon Sep 17 00:00:00 2001 From: munrocket Date: Wed, 25 Jun 2025 11:14:10 +0400 Subject: [PATCH 2/3] fix lint --- src/emulator-manager.ts | 26 +++++++++++++------------- src/main.ts | 26 ++------------------------ 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/src/emulator-manager.ts b/src/emulator-manager.ts index 9f5d69aa0..5a8161627 100644 --- a/src/emulator-manager.ts +++ b/src/emulator-manager.ts @@ -5,18 +5,18 @@ import * as fs from 'fs'; * Creates a new AVD instance with the specified configurations. */ export async function createAvd( - systemImageApiLevel: string, - target: string, arch: string, - profile: string, + avdName: string, cores: string, - ramSize: string, - heapSize: string, - sdcardPathOrSize: string, diskSize: string, - avdName: string, + enableHardwareKeyboard: boolean, forceAvdCreation: boolean, - enableHardwareKeyboard: boolean + heapSize: string, + profile: string, + ramSize: string, + sdcardPathOrSize: string, + systemImageApiLevel: string, + target: string ): Promise { try { console.log(`::group::Create AVD`); @@ -65,13 +65,13 @@ export async function createAvd( */ export async function launchEmulator( avdName: string, - emulatorBootTimeout: number, - port: number, - emulatorOptions: string, disableAnimations: boolean, - disableSpellChecker: boolean, disableLinuxHardwareAcceleration: boolean, - enableHardwareKeyboard: boolean + disableSpellChecker: boolean, + emulatorBootTimeout: number, + emulatorOptions: string, + enableHardwareKeyboard: boolean, + port: number ): Promise { try { console.log(`::group::Launch Emulator`); diff --git a/src/main.ts b/src/main.ts index e144665d6..df521a579 100644 --- a/src/main.ts +++ b/src/main.ts @@ -192,20 +192,7 @@ async function run() { await installAndroidSdk(apiLevel, systemImageApiLevel, target, arch, channelId, emulatorBuild, ndkVersion, cmakeVersion); // create AVD - await createAvd( - systemImageApiLevel, - target, - arch, - profile, - cores, - ramSize, - heapSize, - sdcardPathOrSize, - diskSize, - avdName, - forceAvdCreation, - enableHardwareKeyboard - ); + await createAvd(arch, avdName, cores, diskSize, enableHardwareKeyboard, forceAvdCreation, heapSize, profile, ramSize, sdcardPathOrSize, systemImageApiLevel, target); // execute pre emulator launch script if set if (preEmulatorLaunchScripts !== undefined) { @@ -225,16 +212,7 @@ async function run() { } // launch an emulator - await launchEmulator( - avdName, - emulatorBootTimeout, - port, - emulatorOptions, - disableAnimations, - disableSpellchecker, - disableLinuxHardwareAcceleration, - enableHardwareKeyboard - ); + await launchEmulator(avdName, disableAnimations, disableLinuxHardwareAcceleration, disableSpellchecker, emulatorBootTimeout, emulatorOptions, enableHardwareKeyboard, port); // execute the custom script try { From fd4eaee62d6c57a661fe6ded977d43b2ed82d236 Mon Sep 17 00:00:00 2001 From: munrocket Date: Wed, 25 Jun 2025 17:50:04 +0400 Subject: [PATCH 3/3] update src --- lib/emulator-manager.js | 22 ++++++++++++++++++---- lib/main.js | 4 +++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/emulator-manager.js b/lib/emulator-manager.js index ab84717f9..d57b97e96 100644 --- a/lib/emulator-manager.js +++ b/lib/emulator-manager.js @@ -32,16 +32,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.killEmulator = exports.launchEmulator = void 0; +exports.killEmulator = exports.launchEmulator = exports.createAvd = void 0; const exec = __importStar(require("@actions/exec")); const fs = __importStar(require("fs")); /** - * Creates and launches a new AVD instance with the specified configurations. + * Creates a new AVD instance with the specified configurations. */ -function launchEmulator(systemImageApiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorBootTimeout, port, emulatorOptions, disableAnimations, disableSpellChecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard) { +function createAvd(arch, avdName, cores, diskSize, enableHardwareKeyboard, forceAvdCreation, heapSize, profile, ramSize, sdcardPathOrSize, systemImageApiLevel, target) { return __awaiter(this, void 0, void 0, function* () { try { - console.log(`::group::Launch Emulator`); + console.log(`::group::Create AVD`); // create a new AVD if AVD directory does not already exist or forceAvdCreation is true const avdPath = `${process.env.ANDROID_AVD_HOME}/${avdName}.avd`; if (!fs.existsSync(avdPath) || forceAvdCreation) { @@ -72,6 +72,20 @@ function launchEmulator(systemImageApiLevel, target, arch, profile, cores, ramSi yield exec.exec(`sh -c \\"printf '${configContent}' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini"`); } } + } + finally { + console.log(`::endgroup::`); + } + }); +} +exports.createAvd = createAvd; +/** + * Launches an existing AVD instance with the specified configurations. + */ +function launchEmulator(avdName, disableAnimations, disableLinuxHardwareAcceleration, disableSpellChecker, emulatorBootTimeout, emulatorOptions, enableHardwareKeyboard, port) { + return __awaiter(this, void 0, void 0, function* () { + try { + console.log(`::group::Launch Emulator`); // turn off hardware acceleration on Linux if (process.platform === 'linux' && disableLinuxHardwareAcceleration) { console.log('Disabling Linux hardware acceleration.'); diff --git a/lib/main.js b/lib/main.js index 9bff6cbd7..fd352a44c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -184,6 +184,8 @@ function run() { console.log(`::endgroup::`); // install SDK yield (0, sdk_installer_1.installAndroidSdk)(apiLevel, systemImageApiLevel, target, arch, channelId, emulatorBuild, ndkVersion, cmakeVersion); + // create AVD + yield (0, emulator_manager_1.createAvd)(arch, avdName, cores, diskSize, enableHardwareKeyboard, forceAvdCreation, heapSize, profile, ramSize, sdcardPathOrSize, systemImageApiLevel, target); // execute pre emulator launch script if set if (preEmulatorLaunchScripts !== undefined) { console.log(`::group::Run pre emulator launch script`); @@ -202,7 +204,7 @@ function run() { console.log(`::endgroup::`); } // launch an emulator - yield (0, emulator_manager_1.launchEmulator)(systemImageApiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorBootTimeout, port, emulatorOptions, disableAnimations, disableSpellchecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard); + yield (0, emulator_manager_1.launchEmulator)(avdName, disableAnimations, disableLinuxHardwareAcceleration, disableSpellchecker, emulatorBootTimeout, emulatorOptions, enableHardwareKeyboard, port); // execute the custom script try { // move to custom working directory if set