Skip to content

Commit dfed997

Browse files
committed
Use xvfb-run to run emulator on Linux
1 parent d8da5b6 commit dfed997

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

lib/emulator-manager.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, heapSiz
7070
console.log('Disabling Linux hardware acceleration.');
7171
emulatorOptions += ' -accel off';
7272
}
73+
let emulatorCommandPrefix;
74+
if (process.platform === 'linux') {
75+
emulatorCommandPrefix = 'xvfb-run';
76+
}
7377
// start emulator
7478
console.log('Starting emulator.');
75-
yield exec.exec(`sh -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd "${avdName}" ${emulatorOptions} &"`, [], {
79+
yield exec.exec(`sh -c \\"${emulatorCommandPrefix} ${process.env.ANDROID_HOME}/emulator/emulator -avd "${avdName}" ${emulatorOptions} &"`, [], {
7680
listeners: {
7781
stderr: (data) => {
7882
if (data.toString().includes('invalid command-line parameter')) {

lib/sdk-installer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndk
5252
console.log(`::group::Install Android SDK`);
5353
const isOnMac = process.platform === 'darwin';
5454
const isArm = process.arch === 'arm64';
55+
const isLinux = process.platform === 'linux';
5556
if (!isOnMac) {
5657
yield exec.exec(`sh -c \\"sudo chown $USER:$USER ${process.env.ANDROID_HOME} -R`);
5758
}
@@ -106,6 +107,11 @@ function installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndk
106107
console.log(`Installing CMake ${cmakeVersion}.`);
107108
yield exec.exec(`sh -c \\"sdkmanager --install 'cmake;${cmakeVersion}' --channel=${channelId} > /dev/null"`);
108109
}
110+
if (isLinux) {
111+
console.log('Installing emulator dependencies.');
112+
yield exec.exec(`sh -c \\"sudo apt update"`);
113+
yield exec.exec(`sh -c \\"sudo apt install libpulse0 xvfb"`);
114+
}
109115
}
110116
finally {
111117
console.log(`::endgroup::`);

src/emulator-manager.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,16 @@ export async function launchEmulator(
6262
emulatorOptions += ' -accel off';
6363
}
6464

65+
let emulatorCommandPrefix;
66+
67+
if (process.platform === 'linux') {
68+
emulatorCommandPrefix = 'xvfb-run'
69+
}
70+
6571
// start emulator
6672
console.log('Starting emulator.');
6773

68-
await exec.exec(`sh -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd "${avdName}" ${emulatorOptions} &"`, [], {
74+
await exec.exec(`sh -c \\"${emulatorCommandPrefix} ${process.env.ANDROID_HOME}/emulator/emulator -avd "${avdName}" ${emulatorOptions} &"`, [], {
6975
listeners: {
7076
stderr: (data: Buffer) => {
7177
if (data.toString().includes('invalid command-line parameter')) {

src/sdk-installer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export async function installAndroidSdk(apiLevel: string, target: string, arch:
1818
console.log(`::group::Install Android SDK`);
1919
const isOnMac = process.platform === 'darwin';
2020
const isArm = process.arch === 'arm64';
21+
const isLinux = process.platform === 'linux';
2122

2223
if (!isOnMac) {
2324
await exec.exec(`sh -c \\"sudo chown $USER:$USER ${process.env.ANDROID_HOME} -R`);
@@ -79,6 +80,11 @@ export async function installAndroidSdk(apiLevel: string, target: string, arch:
7980
console.log(`Installing CMake ${cmakeVersion}.`);
8081
await exec.exec(`sh -c \\"sdkmanager --install 'cmake;${cmakeVersion}' --channel=${channelId} > /dev/null"`);
8182
}
83+
if (isLinux) {
84+
console.log('Installing emulator dependencies.');
85+
await exec.exec(`sh -c \\"sudo apt update"`)
86+
await exec.exec(`sh -c \\"sudo apt install libpulse0 xvfb"`)
87+
}
8288
} finally {
8389
console.log(`::endgroup::`);
8490
}

0 commit comments

Comments
 (0)