Skip to content

Commit

Permalink
fix(ubuntu): specify all avd-related environment variables
Browse files Browse the repository at this point in the history
on ubuntu-24 it seems that the AVD is not created where expected,
so we force creation in the AVD home

specifically it was in $HOME/.config/.android instead of $HOME/.android

by setting all the AVD-related variables, avdmanager and emulator work

additionally, we define an avdPath var but were not using it everywhere
possible
  • Loading branch information
mikehardy committed Oct 11, 2024
1 parent 3a18f50 commit 3ca67ba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
10 changes: 5 additions & 5 deletions lib/emulator-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, heapSiz
yield exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n "${avdName}" --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}' ${profileOption} ${sdcardPathOrSizeOption}"`);
}
if (cores) {
yield exec.exec(`sh -c \\"printf 'hw.cpu.ncore=${cores}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
yield exec.exec(`sh -c \\"printf 'hw.cpu.ncore=${cores}\n' >> ${avdPath}"/config.ini`);
}
if (ramSize) {
yield exec.exec(`sh -c \\"printf 'hw.ramSize=${ramSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
yield exec.exec(`sh -c \\"printf 'hw.ramSize=${ramSize}\n' >> ${avdPath}"/config.ini`);
}
if (heapSize) {
yield exec.exec(`sh -c \\"printf 'hw.heapSize=${heapSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
yield exec.exec(`sh -c \\"printf 'hw.heapSize=${heapSize}\n' >> ${avdPath}"/config.ini`);
}
if (enableHardwareKeyboard) {
yield exec.exec(`sh -c \\"printf 'hw.keyboard=yes\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
yield exec.exec(`sh -c \\"printf 'hw.keyboard=yes\n' >> ${avdPath}"/config.ini`);
}
if (diskSize) {
yield exec.exec(`sh -c \\"printf 'disk.dataPartition.size=${diskSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
yield exec.exec(`sh -c \\"printf 'disk.dataPartition.size=${diskSize}\n' >> ${avdPath}"/config.ini`);
}
// turn off hardware acceleration on Linux
if (process.platform === 'linux' && disableLinuxHardwareAcceleration) {
Expand Down
6 changes: 4 additions & 2 deletions lib/sdk-installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ function installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndk
}
// add paths for commandline-tools and platform-tools
core.addPath(`${cmdlineToolsPath}/latest:${cmdlineToolsPath}/latest/bin:${process.env.ANDROID_HOME}/platform-tools`);
// set standard AVD path
core.exportVariable('ANDROID_AVD_HOME', `${process.env.HOME}/.android/avd`);
// set standard AVD home and path variables
core.exportVariable('ANDROID_USER_HOME', `${process.env.HOME}/.android`);
core.exportVariable('ANDROID_EMULATOR_HOME', process.env.ANDROID_USER_HOME);
core.exportVariable('ANDROID_AVD_HOME', `${process.env.ANDROID_EMULATOR_HOME}/avd`);
// accept all Android SDK licenses
yield exec.exec(`sh -c \\"yes | sdkmanager --licenses > /dev/null"`);
console.log('Installing latest build tools, platform tools, and platform.');
Expand Down
10 changes: 5 additions & 5 deletions src/emulator-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ export async function launchEmulator(
}

if (cores) {
await exec.exec(`sh -c \\"printf 'hw.cpu.ncore=${cores}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
await exec.exec(`sh -c \\"printf 'hw.cpu.ncore=${cores}\n' >> ${avdPath}"/config.ini`);
}

if (ramSize) {
await exec.exec(`sh -c \\"printf 'hw.ramSize=${ramSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
await exec.exec(`sh -c \\"printf 'hw.ramSize=${ramSize}\n' >> ${avdPath}"/config.ini`);
}

if (heapSize) {
await exec.exec(`sh -c \\"printf 'hw.heapSize=${heapSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
await exec.exec(`sh -c \\"printf 'hw.heapSize=${heapSize}\n' >> ${avdPath}"/config.ini`);
}

if (enableHardwareKeyboard) {
await exec.exec(`sh -c \\"printf 'hw.keyboard=yes\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
await exec.exec(`sh -c \\"printf 'hw.keyboard=yes\n' >> ${avdPath}"/config.ini`);
}

if (diskSize) {
await exec.exec(`sh -c \\"printf 'disk.dataPartition.size=${diskSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
await exec.exec(`sh -c \\"printf 'disk.dataPartition.size=${diskSize}\n' >> ${avdPath}"/config.ini`);
}

// turn off hardware acceleration on Linux
Expand Down
6 changes: 4 additions & 2 deletions src/sdk-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export async function installAndroidSdk(apiLevel: string, target: string, arch:
// add paths for commandline-tools and platform-tools
core.addPath(`${cmdlineToolsPath}/latest:${cmdlineToolsPath}/latest/bin:${process.env.ANDROID_HOME}/platform-tools`);

// set standard AVD path
core.exportVariable('ANDROID_AVD_HOME', `${process.env.HOME}/.android/avd`);
// set standard AVD home and path variables
core.exportVariable('ANDROID_USER_HOME', `${process.env.HOME}/.android`);
core.exportVariable('ANDROID_EMULATOR_HOME', process.env.ANDROID_USER_HOME);
core.exportVariable('ANDROID_AVD_HOME', `${process.env.ANDROID_EMULATOR_HOME}/avd`);

// accept all Android SDK licenses
await exec.exec(`sh -c \\"yes | sdkmanager --licenses > /dev/null"`);
Expand Down

0 comments on commit 3ca67ba

Please sign in to comment.