Skip to content

Commit

Permalink
Use xvfb-run to run emulator on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalyster committed Mar 29, 2024
1 parent d8da5b6 commit dfed997
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/emulator-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, heapSiz
console.log('Disabling Linux hardware acceleration.');
emulatorOptions += ' -accel off';
}
let emulatorCommandPrefix;
if (process.platform === 'linux') {
emulatorCommandPrefix = 'xvfb-run';
}
// start emulator
console.log('Starting emulator.');
yield exec.exec(`sh -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd "${avdName}" ${emulatorOptions} &"`, [], {
yield exec.exec(`sh -c \\"${emulatorCommandPrefix} ${process.env.ANDROID_HOME}/emulator/emulator -avd "${avdName}" ${emulatorOptions} &"`, [], {
listeners: {
stderr: (data) => {
if (data.toString().includes('invalid command-line parameter')) {
Expand Down
6 changes: 6 additions & 0 deletions lib/sdk-installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndk
console.log(`::group::Install Android SDK`);
const isOnMac = process.platform === 'darwin';
const isArm = process.arch === 'arm64';
const isLinux = process.platform === 'linux';
if (!isOnMac) {
yield exec.exec(`sh -c \\"sudo chown $USER:$USER ${process.env.ANDROID_HOME} -R`);
}
Expand Down Expand Up @@ -106,6 +107,11 @@ function installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndk
console.log(`Installing CMake ${cmakeVersion}.`);
yield exec.exec(`sh -c \\"sdkmanager --install 'cmake;${cmakeVersion}' --channel=${channelId} > /dev/null"`);
}
if (isLinux) {
console.log('Installing emulator dependencies.');
yield exec.exec(`sh -c \\"sudo apt update"`);
yield exec.exec(`sh -c \\"sudo apt install libpulse0 xvfb"`);
}
}
finally {
console.log(`::endgroup::`);
Expand Down
8 changes: 7 additions & 1 deletion src/emulator-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,16 @@ export async function launchEmulator(
emulatorOptions += ' -accel off';
}

let emulatorCommandPrefix;

if (process.platform === 'linux') {
emulatorCommandPrefix = 'xvfb-run'
}

// start emulator
console.log('Starting emulator.');

await exec.exec(`sh -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd "${avdName}" ${emulatorOptions} &"`, [], {
await exec.exec(`sh -c \\"${emulatorCommandPrefix} ${process.env.ANDROID_HOME}/emulator/emulator -avd "${avdName}" ${emulatorOptions} &"`, [], {
listeners: {
stderr: (data: Buffer) => {
if (data.toString().includes('invalid command-line parameter')) {
Expand Down
6 changes: 6 additions & 0 deletions src/sdk-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export async function installAndroidSdk(apiLevel: string, target: string, arch:
console.log(`::group::Install Android SDK`);
const isOnMac = process.platform === 'darwin';
const isArm = process.arch === 'arm64';
const isLinux = process.platform === 'linux';

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

0 comments on commit dfed997

Please sign in to comment.