mirror of
https://github.com/reactivecircus/android-emulator-runner.git
synced 2026-09-04 19:29:31 +00:00
Add support for configuring hardware profile and running custom script.
This commit is contained in:
@@ -17,35 +17,53 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const EMULATOR_BOOT_TIMEOUT_SECONDS = 120;
|
||||
const AVD_MANAGER_PATH = `${process.env.ANDROID_HOME}/tools/bin/avdmanager`;
|
||||
const ADB_PATH = `${process.env.ANDROID_HOME}/platform-tools/adb`;
|
||||
/**
|
||||
* Creates and launches a new AVD instance with the specified configurations.
|
||||
*/
|
||||
function launchEmulator(apiLevel, target, abi, device, headless, disableAnimations) {
|
||||
function launchEmulator(apiLevel, target, arch, profile, headless, disableAnimations) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const avdmangerPath = `${process.env.ANDROID_HOME}/tools/bin/avdmanager`;
|
||||
const adbPath = `${process.env.ANDROID_HOME}/platform-tools/adb`;
|
||||
// create a new AVD
|
||||
console.log('Creating AVD.');
|
||||
yield exec.exec(`${avdmangerPath} create avd -n test --force --abi "${target}/${abi}" --package "system-images;android-${apiLevel};${target};${abi}" --device "${device}"`);
|
||||
if (profile.trim() !== '') {
|
||||
console.log(`Creating AVD with custom profile ${profile}`);
|
||||
yield exec.exec(`${AVD_MANAGER_PATH} create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`);
|
||||
}
|
||||
else {
|
||||
console.log(`Creating AVD without custom profile.`);
|
||||
yield exec.exec(`echo "no" | ${AVD_MANAGER_PATH} create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}"`);
|
||||
}
|
||||
// start emulator
|
||||
console.log('Starting emulator.');
|
||||
const noWindow = headless ? '-no-window' : '';
|
||||
yield exec.exec(`bash -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd test ${noWindow} -no-snapshot -noaudio -no-boot-anim &"`);
|
||||
// wait for emulator to complete booting
|
||||
yield waitForDevice();
|
||||
yield exec.exec(`${adbPath} shell input keyevent 82`);
|
||||
yield exec.exec(`${ADB_PATH} shell input keyevent 82`);
|
||||
// disable animations
|
||||
if (disableAnimations) {
|
||||
console.log('Disabling animations.');
|
||||
yield exec.exec(`${adbPath} shell settings put global window_animation_scale 0.0`);
|
||||
yield exec.exec(`${adbPath} shell settings put global transition_animation_scale 0.0`);
|
||||
yield exec.exec(`${adbPath} shell settings put global animator_duration_scale 0.0`);
|
||||
yield exec.exec(`${ADB_PATH} shell settings put global window_animation_scale 0.0`);
|
||||
yield exec.exec(`${ADB_PATH} shell settings put global transition_animation_scale 0.0`);
|
||||
yield exec.exec(`${ADB_PATH} shell settings put global animator_duration_scale 0.0`);
|
||||
}
|
||||
// kill emulator
|
||||
yield exec.exec(`${adbPath} -s emulator-5554 emu kill`);
|
||||
});
|
||||
}
|
||||
exports.launchEmulator = launchEmulator;
|
||||
/**
|
||||
* Kills the running emulator on the defaut port.
|
||||
*/
|
||||
function killEmulator() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
yield exec.exec(`${ADB_PATH} -s emulator-5554 emu kill`);
|
||||
}
|
||||
catch (error) {
|
||||
console.log('No emulator running on port 5554');
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.killEmulator = killEmulator;
|
||||
/**
|
||||
* Wait for emulator to boot.
|
||||
*/
|
||||
@@ -72,8 +90,8 @@ function waitForDevice() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e.message);
|
||||
catch (error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
if (attempts < maxAttemps) {
|
||||
yield delay(retryInterval * 1000);
|
||||
@@ -2,7 +2,7 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MIN_API_LEVEL = 21;
|
||||
exports.VALID_TARGETS = ['default', 'google_apis'];
|
||||
exports.VALID_ABIS = ['x86', 'x86_64'];
|
||||
exports.VALID_ARCHS = ['x86', 'x86_64'];
|
||||
function checkApiLevel(apiLevel) {
|
||||
if (isNaN(Number(apiLevel)) || !Number.isInteger(Number(apiLevel))) {
|
||||
throw new Error(`Unexpected API level: '${apiLevel}'.`);
|
||||
@@ -18,12 +18,12 @@ function checkTarget(target) {
|
||||
}
|
||||
}
|
||||
exports.checkTarget = checkTarget;
|
||||
function checkAbi(abi) {
|
||||
if (!exports.VALID_ABIS.includes(abi)) {
|
||||
throw new Error(`Value for input.abi '${abi}' is unknown. Supported options: ${exports.VALID_ABIS}.`);
|
||||
function checkArch(arch) {
|
||||
if (!exports.VALID_ARCHS.includes(arch)) {
|
||||
throw new Error(`Value for input.arch '${arch}' is unknown. Supported options: ${exports.VALID_ARCHS}.`);
|
||||
}
|
||||
}
|
||||
exports.checkAbi = checkAbi;
|
||||
exports.checkArch = checkArch;
|
||||
function checkHeadless(headless) {
|
||||
if (headless !== 'true' && headless !== 'false') {
|
||||
throw new Error(`Input for input.headless should be either 'true' or 'false'.`);
|
||||
|
||||
+20
-11
@@ -18,7 +18,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const sdk_installer_1 = require("./sdk-installer");
|
||||
const input_validator_1 = require("./input-validator");
|
||||
const emulator_launcher_1 = require("./emulator-launcher");
|
||||
const emulator_manager_1 = require("./emulator-manager");
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
@@ -35,10 +36,13 @@ function run() {
|
||||
const target = core.getInput('target');
|
||||
input_validator_1.checkTarget(target);
|
||||
console.log(`target: ${target}`);
|
||||
// CPU / ABI of the system image
|
||||
const abi = core.getInput('abi');
|
||||
input_validator_1.checkAbi(abi);
|
||||
console.log(`cpu/abi: ${abi}`);
|
||||
// CPU architecture of the system image
|
||||
const arch = core.getInput('arch');
|
||||
input_validator_1.checkArch(arch);
|
||||
console.log(`CPI architecture: ${arch}`);
|
||||
// Hardware profile used for creating the AVD
|
||||
const profile = core.getInput('profile');
|
||||
console.log(`Hardware profile: ${profile}`);
|
||||
// headless mode
|
||||
const headlessInput = core.getInput('headless');
|
||||
input_validator_1.checkHeadless(headlessInput);
|
||||
@@ -49,15 +53,20 @@ function run() {
|
||||
input_validator_1.checkDisableAnimations(disableAnimationsInput);
|
||||
const disableAnimations = disableAnimationsInput === 'true';
|
||||
console.log(`disable animations: ${disableAnimations}`);
|
||||
// custom scrpt to run
|
||||
const script = core.getInput('script', { required: true });
|
||||
// install SDK
|
||||
yield sdk_installer_1.installAndroidSdk(apiLevel, target, abi);
|
||||
// launch emulator
|
||||
// TODO get from input (source list of all profiles)
|
||||
const device = 'Nexus 6P';
|
||||
yield emulator_launcher_1.launchEmulator(apiLevel, target, abi, device, headless, disableAnimations);
|
||||
// TODO start emulator
|
||||
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch);
|
||||
// launch an emulator
|
||||
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, headless, disableAnimations);
|
||||
// execute the custom script
|
||||
yield exec.exec(`${script}`);
|
||||
// finally kill the emulator
|
||||
yield emulator_manager_1.killEmulator();
|
||||
}
|
||||
catch (error) {
|
||||
// kill the emulator so the action can exit
|
||||
yield emulator_manager_1.killEmulator();
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -18,12 +18,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const tc = __importStar(require("@actions/tool-cache"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const BUILD_TOOLS_VERSION = '29.0.2';
|
||||
const SDK_URL = 'https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip';
|
||||
/**
|
||||
* Downloads and installs the Android SDK for the macOS platform, including SDK platform for the chosen API level, latest build tools, platform tools, Android Emulator,
|
||||
* and the system image for the chosen API level, cpu/abi, and target.
|
||||
* and the system image for the chosen API level, CPU arch, and target.
|
||||
*/
|
||||
function installAndroidSdk(apiLevel, target, abi) {
|
||||
function installAndroidSdk(apiLevel, target, arch) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// download Android SDK if not already installed
|
||||
if (fs.existsSync(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager`)) {
|
||||
@@ -38,8 +39,9 @@ function installAndroidSdk(apiLevel, target, abi) {
|
||||
console.log('Installing build tools, platform tools, platform and system image.');
|
||||
const sdkmangerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
|
||||
yield exec.exec(`echo "y" | ${sdkmangerPath} --licenses > /dev/null`);
|
||||
yield exec.exec(`${sdkmangerPath} tools platform-tools "platforms;android-${apiLevel}"`);
|
||||
yield exec.exec(`${sdkmangerPath} "system-images;android-${apiLevel};${target};${abi}"`);
|
||||
yield exec.exec(`${sdkmangerPath} "build-tools;${BUILD_TOOLS_VERSION}"`);
|
||||
yield exec.exec(`${sdkmangerPath} platform-tools "platforms;android-${apiLevel}"`);
|
||||
yield exec.exec(`${sdkmangerPath} "system-images;android-${apiLevel};${target};${arch}"`);
|
||||
yield exec.exec(`bash -c \\"${sdkmangerPath} --update > /dev/null"`);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user