mirror of
https://github.com/reactivecircus/android-emulator-runner.git
synced 2026-08-31 17:49:33 +00:00
Support running on linux without hardware accleration.
This commit is contained in:
@@ -9,11 +9,17 @@ on:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: macOS-latest
|
||||
timeout-minutes: 10
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: 15
|
||||
strategy:
|
||||
matrix:
|
||||
api-level: [16, 21, 23, 29]
|
||||
os: [macos-latest, ubuntu-latest]
|
||||
api-level: [16, 23, 29]
|
||||
exclude:
|
||||
- os: ubuntu-latest
|
||||
api-level: 23
|
||||
- os: ubuntu-latest
|
||||
api-level: 29
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
@@ -22,14 +22,14 @@ This action automates the process by doing the following:
|
||||
|
||||
## Usage
|
||||
|
||||
Note that this action must be run on a **macOS** VM, e.g. `macOS-latest` or `macOS-10.14`.
|
||||
Note that this action must be run on a **macOS** VM, e.g. `macos-latest` or `macos-10.15`.
|
||||
|
||||
A workflow that uses **android-emulator-runner** to run your instrumented tests on **API 29**:
|
||||
|
||||
```
|
||||
jobs:
|
||||
test:
|
||||
runs-on: macOS-latest
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
@@ -46,7 +46,7 @@ We can also leverage GitHub Actions's build matrix to test across multiple confi
|
||||
```
|
||||
jobs:
|
||||
test:
|
||||
runs-on: macOS-latest
|
||||
runs-on: macos-latest
|
||||
strategy:
|
||||
matrix:
|
||||
api-level: [21, 23, 29]
|
||||
|
||||
@@ -33,6 +33,10 @@ function launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disabl
|
||||
}
|
||||
// start emulator
|
||||
console.log('Starting emulator.');
|
||||
// turn off hardware acceleration on Linux
|
||||
if (process.platform === 'linux') {
|
||||
emulatorOptions += '-accel off';
|
||||
}
|
||||
yield exec.exec(`sh -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd test ${emulatorOptions} &"`, [], {
|
||||
listeners: {
|
||||
stderr: (data) => {
|
||||
|
||||
+9
-9
@@ -24,9 +24,14 @@ const script_parser_1 = require("./script-parser");
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
// only support running on macOS
|
||||
// only support running on macOS or Linux
|
||||
if (process.platform !== 'darwin') {
|
||||
throw new Error('This action is expected to be run within a macOS virtual machine to enable hardware acceleration.');
|
||||
if (process.platform === 'linux') {
|
||||
console.warn(`You're running a Linux VM where hardware acceleration is not available. Please consider using a macOS VM instead to take advantage of native hardware acceleration support provided by HAXM.`);
|
||||
}
|
||||
else {
|
||||
throw new Error('Unsupported virtual machine: please use either macos or ubuntu VM.');
|
||||
}
|
||||
}
|
||||
// API level of the platform and system image
|
||||
const apiLevelInput = core.getInput('api-level', { required: true });
|
||||
@@ -74,13 +79,8 @@ function run() {
|
||||
}));
|
||||
// install SDK
|
||||
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, emulatorBuild);
|
||||
try {
|
||||
// launch an emulator
|
||||
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations);
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
// launch an emulator
|
||||
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations);
|
||||
// execute the custom script
|
||||
try {
|
||||
// move to custom working directory if set
|
||||
|
||||
+13
-9
@@ -18,28 +18,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const BUILD_TOOLS_VERSION = '29.0.3';
|
||||
const CMDLINE_TOOLS_URL = 'https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip';
|
||||
const CMDLINE_TOOLS_URL_MAC = 'https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip';
|
||||
const CMDLINE_TOOLS_URL_LINUX = 'https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip';
|
||||
/**
|
||||
* Installs & updates 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 arch, and target.
|
||||
*/
|
||||
function installAndroidSdk(apiLevel, target, arch, emulatorBuild) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const isOnMac = process.platform === 'darwin';
|
||||
console.log('Installing new cmdline-tools.');
|
||||
yield exec.exec(`mkdir ${process.env.ANDROID_HOME}/cmdline-tools`);
|
||||
yield exec.exec(`curl -fo commandlinetools.zip ${CMDLINE_TOOLS_URL}`);
|
||||
yield exec.exec(`unzip -q commandlinetools.zip -d ${process.env.ANDROID_HOME}/cmdline-tools`);
|
||||
yield exec.exec(`rm -f commandlinetools.zip`);
|
||||
const sdkUrl = isOnMac ? CMDLINE_TOOLS_URL_MAC : CMDLINE_TOOLS_URL_LINUX;
|
||||
yield exec.exec(`sudo mkdir ${process.env.ANDROID_HOME}/cmdline-tools`);
|
||||
yield exec.exec(`curl -fo commandlinetools.zip ${sdkUrl}`);
|
||||
yield exec.exec(`sudo unzip -q commandlinetools.zip -d ${process.env.ANDROID_HOME}/cmdline-tools`);
|
||||
yield exec.exec(`sudo rm -f commandlinetools.zip`);
|
||||
// add paths for commandline-tools and platform-tools
|
||||
core.addPath(`${process.env.ANDROID_HOME}/cmdline-tools/tools:${process.env.ANDROID_HOME}/cmdline-tools/tools/bin:${process.env.ANDROID_HOME}/platform-tools`);
|
||||
yield exec.exec(`sh -c \\"sudo chmod -R 777 ${process.env.ANDROID_HOME}"`);
|
||||
console.log('Installing latest build tools, platform tools, and platform.');
|
||||
yield exec.exec(`sh -c \\"sdkmanager --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
|
||||
if (emulatorBuild) {
|
||||
console.log(`Installing emulator build ${emulatorBuild}.`);
|
||||
yield exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-darwin-${emulatorBuild}.zip`);
|
||||
yield exec.exec(`rm -rf ${process.env.ANDROID_HOME}/emulator`);
|
||||
yield exec.exec(`unzip -q emulator.zip -d ${process.env.ANDROID_HOME}`);
|
||||
yield exec.exec(`rm -f emulator.zip`);
|
||||
yield exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-${isOnMac ? 'darwin' : 'linux'}-${emulatorBuild}.zip`);
|
||||
yield exec.exec(`sudo rm -rf ${process.env.ANDROID_HOME}/emulator`);
|
||||
yield exec.exec(`sudo unzip -q emulator.zip -d ${process.env.ANDROID_HOME}`);
|
||||
yield exec.exec(`sudo rm -f emulator.zip`);
|
||||
}
|
||||
else {
|
||||
console.log('Installing latest emulator.');
|
||||
|
||||
@@ -17,6 +17,12 @@ export async function launchEmulator(apiLevel: number, target: string, arch: str
|
||||
|
||||
// start emulator
|
||||
console.log('Starting emulator.');
|
||||
|
||||
// turn off hardware acceleration on Linux
|
||||
if (process.platform === 'linux') {
|
||||
emulatorOptions += ' -accel off';
|
||||
}
|
||||
|
||||
await exec.exec(`sh -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd test ${emulatorOptions} &"`, [], {
|
||||
listeners: {
|
||||
stderr: (data: Buffer) => {
|
||||
|
||||
+10
-8
@@ -7,9 +7,15 @@ import { parseScript } from './script-parser';
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
// only support running on macOS
|
||||
// only support running on macOS or Linux
|
||||
if (process.platform !== 'darwin') {
|
||||
throw new Error('This action is expected to be run within a macOS virtual machine to enable hardware acceleration.');
|
||||
if (process.platform === 'linux') {
|
||||
console.warn(
|
||||
`You're running a Linux VM where hardware acceleration is not available. Please consider using a macOS VM instead to take advantage of native hardware acceleration support provided by HAXM.`
|
||||
);
|
||||
} else {
|
||||
throw new Error('Unsupported virtual machine: please use either macos or ubuntu VM.');
|
||||
}
|
||||
}
|
||||
|
||||
// API level of the platform and system image
|
||||
@@ -68,12 +74,8 @@ async function run() {
|
||||
// install SDK
|
||||
await installAndroidSdk(apiLevel, target, arch, emulatorBuild);
|
||||
|
||||
try {
|
||||
// launch an emulator
|
||||
await launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
// launch an emulator
|
||||
await launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations);
|
||||
|
||||
// execute the custom script
|
||||
try {
|
||||
|
||||
+14
-9
@@ -2,30 +2,35 @@ import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
const BUILD_TOOLS_VERSION = '29.0.3';
|
||||
const CMDLINE_TOOLS_URL = 'https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip';
|
||||
const CMDLINE_TOOLS_URL_MAC = 'https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip';
|
||||
const CMDLINE_TOOLS_URL_LINUX = 'https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip';
|
||||
|
||||
/**
|
||||
* Installs & updates 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 arch, and target.
|
||||
*/
|
||||
export async function installAndroidSdk(apiLevel: number, target: string, arch: string, emulatorBuild?: string): Promise<void> {
|
||||
const isOnMac = process.platform === 'darwin';
|
||||
console.log('Installing new cmdline-tools.');
|
||||
await exec.exec(`mkdir ${process.env.ANDROID_HOME}/cmdline-tools`);
|
||||
await exec.exec(`curl -fo commandlinetools.zip ${CMDLINE_TOOLS_URL}`);
|
||||
await exec.exec(`unzip -q commandlinetools.zip -d ${process.env.ANDROID_HOME}/cmdline-tools`);
|
||||
await exec.exec(`rm -f commandlinetools.zip`);
|
||||
const sdkUrl = isOnMac ? CMDLINE_TOOLS_URL_MAC : CMDLINE_TOOLS_URL_LINUX;
|
||||
await exec.exec(`sudo mkdir ${process.env.ANDROID_HOME}/cmdline-tools`);
|
||||
await exec.exec(`curl -fo commandlinetools.zip ${sdkUrl}`);
|
||||
await exec.exec(`sudo unzip -q commandlinetools.zip -d ${process.env.ANDROID_HOME}/cmdline-tools`);
|
||||
await exec.exec(`sudo rm -f commandlinetools.zip`);
|
||||
|
||||
// add paths for commandline-tools and platform-tools
|
||||
core.addPath(`${process.env.ANDROID_HOME}/cmdline-tools/tools:${process.env.ANDROID_HOME}/cmdline-tools/tools/bin:${process.env.ANDROID_HOME}/platform-tools`);
|
||||
await exec.exec(`sh -c \\"sudo chmod -R 777 ${process.env.ANDROID_HOME}"`);
|
||||
|
||||
console.log('Installing latest build tools, platform tools, and platform.');
|
||||
|
||||
await exec.exec(`sh -c \\"sdkmanager --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
|
||||
if (emulatorBuild) {
|
||||
console.log(`Installing emulator build ${emulatorBuild}.`);
|
||||
await exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-darwin-${emulatorBuild}.zip`);
|
||||
await exec.exec(`rm -rf ${process.env.ANDROID_HOME}/emulator`);
|
||||
await exec.exec(`unzip -q emulator.zip -d ${process.env.ANDROID_HOME}`);
|
||||
await exec.exec(`rm -f emulator.zip`);
|
||||
await exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-${isOnMac ? 'darwin' : 'linux'}-${emulatorBuild}.zip`);
|
||||
await exec.exec(`sudo rm -rf ${process.env.ANDROID_HOME}/emulator`);
|
||||
await exec.exec(`sudo unzip -q emulator.zip -d ${process.env.ANDROID_HOME}`);
|
||||
await exec.exec(`sudo rm -f emulator.zip`);
|
||||
} else {
|
||||
console.log('Installing latest emulator.');
|
||||
await exec.exec(`sh -c \\"sdkmanager --install emulator > /dev/null"`);
|
||||
|
||||
Reference in New Issue
Block a user