Skip to content

Commit f2bf410

Browse files
authored
Fix pre-emulator-launch-script (#439)
1 parent 62e6348 commit f2bf410

File tree

4 files changed

+57
-43
lines changed

4 files changed

+57
-43
lines changed

lib/emulator-manager.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
3232
});
3333
};
3434
Object.defineProperty(exports, "__esModule", { value: true });
35-
exports.killEmulator = exports.launchEmulator = void 0;
35+
exports.killEmulator = exports.launchEmulator = exports.createAvd = void 0;
3636
const exec = __importStar(require("@actions/exec"));
3737
const fs = __importStar(require("fs"));
3838
/**
39-
* Creates and launches a new AVD instance with the specified configurations.
39+
* Creates a new AVD instance with the specified configurations.
4040
*/
41-
function launchEmulator(systemImageApiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorBootTimeout, port, emulatorOptions, disableAnimations, disableSpellChecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard) {
41+
function createAvd(arch, avdName, cores, diskSize, enableHardwareKeyboard, forceAvdCreation, heapSize, profile, ramSize, sdcardPathOrSize, systemImageApiLevel, target) {
4242
return __awaiter(this, void 0, void 0, function* () {
4343
try {
44-
console.log(`::group::Launch Emulator`);
44+
console.log(`::group::Create AVD`);
4545
// create a new AVD if AVD directory does not already exist or forceAvdCreation is true
4646
const avdPath = `${process.env.ANDROID_AVD_HOME}/${avdName}.avd`;
4747
if (!fs.existsSync(avdPath) || forceAvdCreation) {
@@ -72,6 +72,20 @@ function launchEmulator(systemImageApiLevel, target, arch, profile, cores, ramSi
7272
yield exec.exec(`sh -c \\"printf '${configContent}' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini"`);
7373
}
7474
}
75+
}
76+
finally {
77+
console.log(`::endgroup::`);
78+
}
79+
});
80+
}
81+
exports.createAvd = createAvd;
82+
/**
83+
* Launches an existing AVD instance with the specified configurations.
84+
*/
85+
function launchEmulator(avdName, disableAnimations, disableLinuxHardwareAcceleration, disableSpellChecker, emulatorBootTimeout, emulatorOptions, enableHardwareKeyboard, port) {
86+
return __awaiter(this, void 0, void 0, function* () {
87+
try {
88+
console.log(`::group::Launch Emulator`);
7589
// turn off hardware acceleration on Linux
7690
if (process.platform === 'linux' && disableLinuxHardwareAcceleration) {
7791
console.log('Disabling Linux hardware acceleration.');

lib/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ function run() {
184184
console.log(`::endgroup::`);
185185
// install SDK
186186
yield (0, sdk_installer_1.installAndroidSdk)(apiLevel, systemImageApiLevel, target, arch, channelId, emulatorBuild, ndkVersion, cmakeVersion);
187+
// create AVD
188+
yield (0, emulator_manager_1.createAvd)(arch, avdName, cores, diskSize, enableHardwareKeyboard, forceAvdCreation, heapSize, profile, ramSize, sdcardPathOrSize, systemImageApiLevel, target);
187189
// execute pre emulator launch script if set
188190
if (preEmulatorLaunchScripts !== undefined) {
189191
console.log(`::group::Run pre emulator launch script`);
@@ -202,7 +204,7 @@ function run() {
202204
console.log(`::endgroup::`);
203205
}
204206
// launch an emulator
205-
yield (0, emulator_manager_1.launchEmulator)(systemImageApiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorBootTimeout, port, emulatorOptions, disableAnimations, disableSpellchecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard);
207+
yield (0, emulator_manager_1.launchEmulator)(avdName, disableAnimations, disableLinuxHardwareAcceleration, disableSpellchecker, emulatorBootTimeout, emulatorOptions, enableHardwareKeyboard, port);
206208
// execute the custom script
207209
try {
208210
// move to custom working directory if set

src/emulator-manager.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,24 @@ 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(
8-
systemImageApiLevel: string,
9-
target: string,
7+
export async function createAvd(
108
arch: string,
11-
profile: string,
9+
avdName: string,
1210
cores: string,
13-
ramSize: string,
14-
heapSize: string,
15-
sdcardPathOrSize: string,
1611
diskSize: string,
17-
avdName: string,
12+
enableHardwareKeyboard: boolean,
1813
forceAvdCreation: boolean,
19-
emulatorBootTimeout: number,
20-
port: number,
21-
emulatorOptions: string,
22-
disableAnimations: boolean,
23-
disableSpellChecker: boolean,
24-
disableLinuxHardwareAcceleration: boolean,
25-
enableHardwareKeyboard: boolean
14+
heapSize: string,
15+
profile: string,
16+
ramSize: string,
17+
sdcardPathOrSize: string,
18+
systemImageApiLevel: string,
19+
target: string
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+
disableAnimations: boolean,
69+
disableLinuxHardwareAcceleration: boolean,
70+
disableSpellChecker: boolean,
71+
emulatorBootTimeout: number,
72+
emulatorOptions: string,
73+
enableHardwareKeyboard: boolean,
74+
port: number
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: 5 additions & 21 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,9 @@ async function run() {
191191
// install SDK
192192
await installAndroidSdk(apiLevel, systemImageApiLevel, target, arch, channelId, emulatorBuild, ndkVersion, cmakeVersion);
193193

194+
// create AVD
195+
await createAvd(arch, avdName, cores, diskSize, enableHardwareKeyboard, forceAvdCreation, heapSize, profile, ramSize, sdcardPathOrSize, systemImageApiLevel, target);
196+
194197
// execute pre emulator launch script if set
195198
if (preEmulatorLaunchScripts !== undefined) {
196199
console.log(`::group::Run pre emulator launch script`);
@@ -209,26 +212,7 @@ async function run() {
209212
}
210213

211214
// launch an emulator
212-
await launchEmulator(
213-
systemImageApiLevel,
214-
target,
215-
arch,
216-
profile,
217-
cores,
218-
ramSize,
219-
heapSize,
220-
sdcardPathOrSize,
221-
diskSize,
222-
avdName,
223-
forceAvdCreation,
224-
emulatorBootTimeout,
225-
port,
226-
emulatorOptions,
227-
disableAnimations,
228-
disableSpellchecker,
229-
disableLinuxHardwareAcceleration,
230-
enableHardwareKeyboard
231-
);
215+
await launchEmulator(avdName, disableAnimations, disableLinuxHardwareAcceleration, disableSpellchecker, emulatorBootTimeout, emulatorOptions, enableHardwareKeyboard, port);
232216

233217
// execute the custom script
234218
try {

0 commit comments

Comments
 (0)