Skip to content

Commit 1b2f005

Browse files
committed
fix pre-launch-script
1 parent 62e6348 commit 1b2f005

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

src/emulator-manager.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as exec from '@actions/exec';
22
import * as fs from 'fs';
33

44
/**
5-
* Creates and launches a new AVD instance with the specified configurations.
5+
* Creates a new AVD instance with the specified configurations.
66
*/
7-
export async function launchEmulator(
7+
export async function createAvd(
88
systemImageApiLevel: string,
99
target: string,
1010
arch: string,
@@ -16,16 +16,10 @@ export async function launchEmulator(
1616
diskSize: string,
1717
avdName: string,
1818
forceAvdCreation: boolean,
19-
emulatorBootTimeout: number,
20-
port: number,
21-
emulatorOptions: string,
22-
disableAnimations: boolean,
23-
disableSpellChecker: boolean,
24-
disableLinuxHardwareAcceleration: boolean,
2519
enableHardwareKeyboard: boolean
2620
): Promise<void> {
2721
try {
28-
console.log(`::group::Launch Emulator`);
22+
console.log(`::group::Create AVD`);
2923
// create a new AVD if AVD directory does not already exist or forceAvdCreation is true
3024
const avdPath = `${process.env.ANDROID_AVD_HOME}/${avdName}.avd`;
3125
if (!fs.existsSync(avdPath) || forceAvdCreation) {
@@ -61,6 +55,26 @@ export async function launchEmulator(
6155
await exec.exec(`sh -c \\"printf '${configContent}' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini"`);
6256
}
6357
}
58+
} finally {
59+
console.log(`::endgroup::`);
60+
}
61+
}
62+
63+
/**
64+
* Launches an existing AVD instance with the specified configurations.
65+
*/
66+
export async function launchEmulator(
67+
avdName: string,
68+
emulatorBootTimeout: number,
69+
port: number,
70+
emulatorOptions: string,
71+
disableAnimations: boolean,
72+
disableSpellChecker: boolean,
73+
disableLinuxHardwareAcceleration: boolean,
74+
enableHardwareKeyboard: boolean
75+
): Promise<void> {
76+
try {
77+
console.log(`::group::Launch Emulator`);
6478

6579
// turn off hardware acceleration on Linux
6680
if (process.platform === 'linux' && disableLinuxHardwareAcceleration) {

src/main.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
checkPort,
1515
MIN_PORT,
1616
} from './input-validator';
17-
import { launchEmulator, killEmulator } from './emulator-manager';
17+
import { createAvd, launchEmulator, killEmulator } from './emulator-manager';
1818
import * as exec from '@actions/exec';
1919
import { parseScript } from './script-parser';
2020
import { getChannelId } from './channel-id-mapper';
@@ -191,6 +191,22 @@ async function run() {
191191
// install SDK
192192
await installAndroidSdk(apiLevel, systemImageApiLevel, target, arch, channelId, emulatorBuild, ndkVersion, cmakeVersion);
193193

194+
// create AVD
195+
await createAvd(
196+
systemImageApiLevel,
197+
target,
198+
arch,
199+
profile,
200+
cores,
201+
ramSize,
202+
heapSize,
203+
sdcardPathOrSize,
204+
diskSize,
205+
avdName,
206+
forceAvdCreation,
207+
enableHardwareKeyboard
208+
);
209+
194210
// execute pre emulator launch script if set
195211
if (preEmulatorLaunchScripts !== undefined) {
196212
console.log(`::group::Run pre emulator launch script`);
@@ -210,17 +226,7 @@ async function run() {
210226

211227
// launch an emulator
212228
await launchEmulator(
213-
systemImageApiLevel,
214-
target,
215-
arch,
216-
profile,
217-
cores,
218-
ramSize,
219-
heapSize,
220-
sdcardPathOrSize,
221-
diskSize,
222229
avdName,
223-
forceAvdCreation,
224230
emulatorBootTimeout,
225231
port,
226232
emulatorOptions,

0 commit comments

Comments
 (0)