mirror of
https://github.com/reactivecircus/android-emulator-runner.git
synced 2026-09-04 03:19:33 +00:00
Add emulator-launcher.
This commit is contained in:
@@ -7,13 +7,84 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const EMULATOR_BOOT_TIMEOUT_SECONDS = 120;
|
||||
/**
|
||||
* Creates and launches a new AVD instance with the specified configurations.
|
||||
*/
|
||||
function startEmulator() {
|
||||
function launchEmulator(apiLevel, target, abi, device, headless, disableAnimations) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// TODO
|
||||
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}"`);
|
||||
// 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`);
|
||||
// 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`);
|
||||
}
|
||||
// kill emulator
|
||||
yield exec.exec(`${adbPath} -s emulator-5554 emu kill`);
|
||||
});
|
||||
}
|
||||
exports.startEmulator = startEmulator;
|
||||
exports.launchEmulator = launchEmulator;
|
||||
/**
|
||||
* Wait for emulator to boot.
|
||||
*/
|
||||
function waitForDevice() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const adbPath = `${process.env.ANDROID_HOME}/platform-tools/adb`;
|
||||
let booted = false;
|
||||
let attempts = 0;
|
||||
const retryInterval = 2; // retry every 2 seconds
|
||||
const maxAttemps = EMULATOR_BOOT_TIMEOUT_SECONDS / 2;
|
||||
while (!booted) {
|
||||
try {
|
||||
let result = '';
|
||||
yield exec.exec(`${adbPath} shell getprop sys.boot_completed`, [], {
|
||||
listeners: {
|
||||
stdout: (data) => {
|
||||
result += data.toString();
|
||||
}
|
||||
}
|
||||
});
|
||||
if (result.trim() === '1') {
|
||||
console.log('Emulator booted.');
|
||||
booted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
if (attempts < maxAttemps) {
|
||||
yield delay(retryInterval * 1000);
|
||||
}
|
||||
else {
|
||||
throw new Error(`Timeout waiting for emulator to boot.`);
|
||||
}
|
||||
attempts++;
|
||||
}
|
||||
});
|
||||
}
|
||||
function delay(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
@@ -30,3 +30,9 @@ function checkHeadless(headless) {
|
||||
}
|
||||
}
|
||||
exports.checkHeadless = checkHeadless;
|
||||
function checkDisableAnimations(disableAnimations) {
|
||||
if (disableAnimations !== 'true' && disableAnimations !== 'false') {
|
||||
throw new Error(`Input for input.disable-animations should be either 'true' or 'false'.`);
|
||||
}
|
||||
}
|
||||
exports.checkDisableAnimations = checkDisableAnimations;
|
||||
|
||||
+17
-5
@@ -18,6 +18,7 @@ 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");
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
@@ -26,8 +27,9 @@ function run() {
|
||||
throw new Error('This action is expected to be run within a macOS virtual machine to enable hardware acceleration.');
|
||||
}
|
||||
// API level of the platform and system image
|
||||
const apiLevel = core.getInput('api-level', { required: true });
|
||||
input_validator_1.checkApiLevel(apiLevel);
|
||||
const apiLevelInput = core.getInput('api-level', { required: true });
|
||||
input_validator_1.checkApiLevel(apiLevelInput);
|
||||
const apiLevel = Number(apiLevelInput);
|
||||
console.log(`API level: ${apiLevel}`);
|
||||
// target of the system image
|
||||
const target = core.getInput('target');
|
||||
@@ -38,11 +40,21 @@ function run() {
|
||||
input_validator_1.checkAbi(abi);
|
||||
console.log(`cpu/abi: ${abi}`);
|
||||
// headless mode
|
||||
const headless = core.getInput('headless');
|
||||
input_validator_1.checkHeadless(headless);
|
||||
const headlessInput = core.getInput('headless');
|
||||
input_validator_1.checkHeadless(headlessInput);
|
||||
const headless = headlessInput === 'true';
|
||||
console.log(`headless mode: ${headless}`);
|
||||
// disable animations
|
||||
const disableAnimationsInput = core.getInput('disable-animations');
|
||||
input_validator_1.checkDisableAnimations(disableAnimationsInput);
|
||||
const disableAnimations = disableAnimationsInput === 'true';
|
||||
console.log(`disable animations: ${disableAnimations}`);
|
||||
// install SDK
|
||||
yield sdk_installer_1.installAndroidSdk(Number(apiLevel), target, abi);
|
||||
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
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
@@ -18,7 +18,6 @@ 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,
|
||||
@@ -37,11 +36,11 @@ function installAndroidSdk(apiLevel, target, abi) {
|
||||
}
|
||||
// install specific SDK tools
|
||||
console.log('Installing build tools, platform tools, platform and system image.');
|
||||
yield exec.exec(`echo "y" | ${process.env.ANDROID_HOME}/tools/bin/sdkmanager --licenses > /dev/null`);
|
||||
yield exec.exec(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager "build-tools;${BUILD_TOOLS_VERSION}"`);
|
||||
yield exec.exec(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager "platform-tools"`);
|
||||
yield exec.exec(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager "platforms;android-${apiLevel}"`);
|
||||
yield exec.exec(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager "system-images;android-${apiLevel};${target};${abi}"`);
|
||||
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(`bash -c \\"${sdkmangerPath} --update > /dev/null"`);
|
||||
});
|
||||
}
|
||||
exports.installAndroidSdk = installAndroidSdk;
|
||||
|
||||
Reference in New Issue
Block a user