mirror of
https://github.com/reactivecircus/android-emulator-runner.git
synced 2026-09-04 03:19:33 +00:00
Initial commit.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Creates and launches a new AVD instance with the specified configurations.
|
||||
*/
|
||||
export async function startEmulator(
|
||||
|
||||
): Promise<void> {
|
||||
// TODO
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
import * as core from '@actions/core';
|
||||
import { installAndroidSdk } from './sdk-installer'
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
// only support running on macOS
|
||||
if (process.platform !== 'darwin') {
|
||||
throw new Error('This action is expected to be run within a macOS virtual machine to enable hardware acceleration.');
|
||||
}
|
||||
|
||||
// TODO test inputs
|
||||
// TODO test real inputs in test.yml
|
||||
|
||||
// api-level is required
|
||||
// TODO use InputOptions {true}
|
||||
const apiLevel = core.getInput('api-level');
|
||||
// TODO check apiLevel is number and within valid range
|
||||
console.log(`API level - ${apiLevel}`);
|
||||
|
||||
// target is optional with default
|
||||
const target = core.getInput('target');
|
||||
if (target !== 'default' && target !== 'google_apis') {
|
||||
throw new Error(`Target ${target} is unknown. Please use either 'default' or 'google_apis'.`);
|
||||
}
|
||||
console.log(`target - ${target}`);
|
||||
|
||||
// abi is optional with default
|
||||
const abi = core.getInput('abi');
|
||||
if (abi !== 'x86' && abi !== 'x86_64') {
|
||||
throw new Error(`abi ${abi} is unknown (ARM-based emulators are not supported). Please use either 'x86' or 'x86_64'.`);
|
||||
}
|
||||
console.log(`cpu/abi - ${abi}`);
|
||||
|
||||
// headless is optional with default
|
||||
const headless = core.getInput('headless');
|
||||
if (headless !== 'true' && headless !== 'false') {
|
||||
throw new Error(`Input 'headless' should be either 'true' or 'false'.`);
|
||||
}
|
||||
console.log(`headless mode - ${headless}`);
|
||||
|
||||
// install SDK
|
||||
await installAndroidSdk(Number(apiLevel), target, abi);
|
||||
|
||||
// TODO start emulator
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
@@ -0,0 +1,30 @@
|
||||
import * as exec from '@actions/exec';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import * as fs from '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.
|
||||
*/
|
||||
export async function installAndroidSdk(apiLevel: number, abi: string, target: string): Promise<void> {
|
||||
// download Android SDK if not already installed
|
||||
if (fs.existsSync(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager`)) {
|
||||
console.log('Android SDK already installed.');
|
||||
} else {
|
||||
console.log('Downloading Android SDK.');
|
||||
const downloadedSdkPath = await tc.downloadTool(SDK_URL);
|
||||
await tc.extractZip(downloadedSdkPath, process.env.ANDROID_HOME);
|
||||
}
|
||||
|
||||
// install specific SDK tools
|
||||
console.log('Installing build tools, platform tools, platform and system image.');
|
||||
await exec.exec(`yes | ${process.env.ANDROID_HOME}/tools/bin/sdkmanager --licenses`);
|
||||
await exec.exec(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager --update`);
|
||||
await exec.exec(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager "build-tools;${BUILD_TOOLS_VERSION}"`);
|
||||
await exec.exec(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager "platform-tools"`);
|
||||
await exec.exec(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager "platforms;android-${apiLevel}"`);
|
||||
await exec.exec(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager "system-images;android-${apiLevel};${target};${abi}"`);
|
||||
}
|
||||
Reference in New Issue
Block a user