Skip to content

Commit

Permalink
fix(ubuntu): specify all avd-related environment variables
Browse files Browse the repository at this point in the history
Allow for users to modify android install directories via standard
environment variables if desired by not clobbering env vars without
checking first

Define all the standard environment variables used in an emulator context
  • Loading branch information
mikehardy committed Oct 13, 2024
1 parent c77bfe7 commit 2d7a205
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
22 changes: 19 additions & 3 deletions lib/sdk-installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,25 @@ 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
yield io.mkdirP(`${process.env.HOME}/.android/avd`);
core.exportVariable('ANDROID_AVD_HOME', `${process.env.HOME}/.android/avd`);
// There are several environment variables that determine where AVD config and disk images go:
// https://developer.android.com/tools/variables#envar
// Users may set these for various reasons (self-hosted runners with specific disk space situations)
// so only set them if they are not already set.
// "user preferences directory for tools that are part of the Android SDK. Defaults to $HOME/.android/."
if (!process.env.ANDROID_USER_HOME) {
core.exportVariable('ANDROID_USER_HOME', `${process.env.HOME}/.android`);
}
yield io.mkdirP(`${process.env.ANDROID_USER_HOME}`);
// "user-specific emulator configuration directory. Defaults to $ANDROID_USER_HOME"
if (!process.env.ANDROID_EMULATOR_HOME) {
core.exportVariable('ANDROID_EMULATOR_HOME', process.env.ANDROID_USER_HOME);
}
yield io.mkdirP(`${process.env.ANDROID_EMULATOR_HOME}`);
// "all AVD-specific files, which mostly consist of very large disk images. Default is $ANDROID_EMULATOR_HOME/avd/"
if (!process.env.ANDROID_AVD_HOME) {
core.exportVariable('ANDROID_AVD_HOME', `${process.env.ANDROID_EMULATOR_HOME}/avd`);
}
yield io.mkdirP(`${process.env.ANDROID_AVD_HOME}`);
// 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
25 changes: 22 additions & 3 deletions src/sdk-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,28 @@ 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
await io.mkdirP(`${process.env.HOME}/.android/avd`);
core.exportVariable('ANDROID_AVD_HOME', `${process.env.HOME}/.android/avd`);
// There are several environment variables that determine where AVD config and disk images go:
// https://developer.android.com/tools/variables#envar
// Users may set these for various reasons (self-hosted runners with specific disk space situations)
// so only set them if they are not already set.

// "user preferences directory for tools that are part of the Android SDK. Defaults to $HOME/.android/."
if (!process.env.ANDROID_USER_HOME) {
core.exportVariable('ANDROID_USER_HOME', `${process.env.HOME}/.android`);
}
await io.mkdirP(`${process.env.ANDROID_USER_HOME}`);

// "user-specific emulator configuration directory. Defaults to $ANDROID_USER_HOME"
if (!process.env.ANDROID_EMULATOR_HOME) {
core.exportVariable('ANDROID_EMULATOR_HOME', process.env.ANDROID_USER_HOME);
}
await io.mkdirP(`${process.env.ANDROID_EMULATOR_HOME}`);

// "all AVD-specific files, which mostly consist of very large disk images. Default is $ANDROID_EMULATOR_HOME/avd/"
if (!process.env.ANDROID_AVD_HOME) {
core.exportVariable('ANDROID_AVD_HOME', `${process.env.ANDROID_EMULATOR_HOME}/avd`);
}
await io.mkdirP(`${process.env.ANDROID_AVD_HOME}`);

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

0 comments on commit 2d7a205

Please sign in to comment.