Skip to content

Commit 769ff28

Browse files
committed
Merge branch 'master' into release/v2
* master: Prepare for release 2.6.0. Update packages. Add information re. hardware acceleration for linux support. Support running on linux without hardware accleration. Gradle 6.3. Gradle 6.3-rc-4. Update workflow to use Java 14. Update npm packages. Bump acorn from 5.7.3 to 5.7.4
2 parents 6bb3965 + 0d96655 commit 769ff28

File tree

12 files changed

+2862
-2091
lines changed

12 files changed

+2862
-2091
lines changed

.github/workflows/workflow.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ on:
99

1010
jobs:
1111
test:
12-
runs-on: macOS-latest
13-
timeout-minutes: 10
12+
runs-on: ${{ matrix.os }}
13+
timeout-minutes: 15
1414
strategy:
1515
matrix:
16-
api-level: [16, 21, 23, 29]
16+
os: [macos-latest, ubuntu-latest]
17+
api-level: [16, 23, 29]
18+
exclude:
19+
- os: ubuntu-latest
20+
api-level: 23
21+
- os: ubuntu-latest
22+
api-level: 29
1723
steps:
1824
- name: checkout
1925
uses: actions/checkout@v2
@@ -28,10 +34,10 @@ jobs:
2834
npm run lint
2935
npm test
3036
31-
- name: Java 13
37+
- name: Java 14
3238
uses: actions/setup-java@v1
3339
with:
34-
java-version: 13
40+
java-version: 14
3541

3642
- name: run action
3743
uses: ./

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## v2.6.0
4+
5+
* Added support for Linux VMs (no hardware acceleration).
6+
37
## v2.5.0
48

59
* Added support for API 15-19 system images.

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<a href="https://github.com/ReactiveCircus/android-emulator-runner"><img alt="GitHub Actions status" src="https://github.com/ReactiveCircus/android-emulator-runner/workflows/Main%20workflow/badge.svg"></a>
55
</p>
66

7-
A GitHub Action for installing, configuring and running Android Emulators on macOS virtual machines.
7+
A GitHub Action for installing, configuring and running hardware-accelerated Android Emulators on macOS virtual machines (or Linux virtual machines but without hardware accleration).
88

99
The old ARM-based emulators were slow and are no longer supported by Google. The modern Intel Atom (x86 and x86_64) emulators require hardware acceleration (HAXM on Mac & Windows, QEMU on Linux) from the host to run fast. This presents a challenge on CI as to be able to run hardware accelerated emulators within a docker container, **KVM** must be supported by the host VM which isn't the case for cloud-based CI providers due to infrastructural limits. If you want to learn more about this, here's an article I wrote: [Running Android Instrumented Tests on CI](https://dev.to/ychescale9/running-android-emulators-on-ci-from-bitrise-io-to-github-actions-3j76).
1010

@@ -22,14 +22,16 @@ This action automates the process by doing the following:
2222

2323
## Usage
2424

25-
Note that this action must be run on a **macOS** VM, e.g. `macOS-latest` or `macOS-10.14`.
25+
It is recommended to run this action on a **macOS** VM, e.g. `macos-latest` or `macos-10.15` to take advantage of hardware accleration support provided by **HAXM**.
26+
27+
Please note that while Linux VMs (e.g. `ubuntu-latest` or `ubuntu-18.04`) are also supported, hardware acceleration will **not** be available.
2628

2729
A workflow that uses **android-emulator-runner** to run your instrumented tests on **API 29**:
2830

2931
```
3032
jobs:
3133
test:
32-
runs-on: macOS-latest
34+
runs-on: macos-latest
3335
steps:
3436
- name: checkout
3537
uses: actions/checkout@v2
@@ -46,7 +48,7 @@ We can also leverage GitHub Actions's build matrix to test across multiple confi
4648
```
4749
jobs:
4850
test:
49-
runs-on: macOS-latest
51+
runs-on: macos-latest
5052
strategy:
5153
matrix:
5254
api-level: [21, 23, 29]
@@ -80,3 +82,5 @@ jobs:
8082
| `script` | Required | N/A | Custom script to run - e.g. to run Android instrumented tests on the emulator: `./gradlew connectedCheck` |
8183

8284
Default `emulator-options`: `-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim`.
85+
86+
_Please note that if you are running on a Linux VM, `-no-accel` will be added to the `emulator-options` to make sure hardware acceleration is turned off._

lib/emulator-manager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ function launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disabl
3333
}
3434
// start emulator
3535
console.log('Starting emulator.');
36+
// turn off hardware acceleration on Linux
37+
if (process.platform === 'linux') {
38+
emulatorOptions += ' -accel off';
39+
}
3640
yield exec.exec(`sh -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd test ${emulatorOptions} &"`, [], {
3741
listeners: {
3842
stderr: (data) => {

lib/main.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ const script_parser_1 = require("./script-parser");
2424
function run() {
2525
return __awaiter(this, void 0, void 0, function* () {
2626
try {
27-
// only support running on macOS
27+
// only support running on macOS or Linux
2828
if (process.platform !== 'darwin') {
29-
throw new Error('This action is expected to be run within a macOS virtual machine to enable hardware acceleration.');
29+
if (process.platform === 'linux') {
30+
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.`);
31+
}
32+
else {
33+
throw new Error('Unsupported virtual machine: please use either macos or ubuntu VM.');
34+
}
3035
}
3136
// API level of the platform and system image
3237
const apiLevelInput = core.getInput('api-level', { required: true });
@@ -74,13 +79,8 @@ function run() {
7479
}));
7580
// install SDK
7681
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, emulatorBuild);
77-
try {
78-
// launch an emulator
79-
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations);
80-
}
81-
catch (error) {
82-
core.setFailed(error.message);
83-
}
82+
// launch an emulator
83+
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations);
8484
// execute the custom script
8585
try {
8686
// move to custom working directory if set

lib/sdk-installer.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
1818
const core = __importStar(require("@actions/core"));
1919
const exec = __importStar(require("@actions/exec"));
2020
const BUILD_TOOLS_VERSION = '29.0.3';
21-
const CMDLINE_TOOLS_URL = 'https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip';
21+
const CMDLINE_TOOLS_URL_MAC = 'https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip';
22+
const CMDLINE_TOOLS_URL_LINUX = 'https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip';
2223
/**
2324
* Installs & updates the Android SDK for the macOS platform, including SDK platform for the chosen API level, latest build tools, platform tools, Android Emulator,
2425
* and the system image for the chosen API level, CPU arch, and target.
2526
*/
2627
function installAndroidSdk(apiLevel, target, arch, emulatorBuild) {
2728
return __awaiter(this, void 0, void 0, function* () {
29+
const isOnMac = process.platform === 'darwin';
2830
console.log('Installing new cmdline-tools.');
29-
yield exec.exec(`mkdir ${process.env.ANDROID_HOME}/cmdline-tools`);
30-
yield exec.exec(`curl -fo commandlinetools.zip ${CMDLINE_TOOLS_URL}`);
31-
yield exec.exec(`unzip -q commandlinetools.zip -d ${process.env.ANDROID_HOME}/cmdline-tools`);
32-
yield exec.exec(`rm -f commandlinetools.zip`);
31+
const sdkUrl = isOnMac ? CMDLINE_TOOLS_URL_MAC : CMDLINE_TOOLS_URL_LINUX;
32+
yield exec.exec(`sudo mkdir ${process.env.ANDROID_HOME}/cmdline-tools`);
33+
yield exec.exec(`curl -fo commandlinetools.zip ${sdkUrl}`);
34+
yield exec.exec(`sudo unzip -q commandlinetools.zip -d ${process.env.ANDROID_HOME}/cmdline-tools`);
35+
yield exec.exec(`sudo rm -f commandlinetools.zip`);
3336
// add paths for commandline-tools and platform-tools
3437
core.addPath(`${process.env.ANDROID_HOME}/cmdline-tools/tools:${process.env.ANDROID_HOME}/cmdline-tools/tools/bin:${process.env.ANDROID_HOME}/platform-tools`);
38+
yield exec.exec(`sh -c \\"sudo chmod -R 777 ${process.env.ANDROID_HOME}"`);
3539
console.log('Installing latest build tools, platform tools, and platform.');
3640
yield exec.exec(`sh -c \\"sdkmanager --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
3741
if (emulatorBuild) {
3842
console.log(`Installing emulator build ${emulatorBuild}.`);
39-
yield exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-darwin-${emulatorBuild}.zip`);
40-
yield exec.exec(`rm -rf ${process.env.ANDROID_HOME}/emulator`);
41-
yield exec.exec(`unzip -q emulator.zip -d ${process.env.ANDROID_HOME}`);
42-
yield exec.exec(`rm -f emulator.zip`);
43+
yield exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-${isOnMac ? 'darwin' : 'linux'}-${emulatorBuild}.zip`);
44+
yield exec.exec(`sudo rm -rf ${process.env.ANDROID_HOME}/emulator`);
45+
yield exec.exec(`sudo unzip -q emulator.zip -d ${process.env.ANDROID_HOME}`);
46+
yield exec.exec(`sudo rm -f emulator.zip`);
4347
}
4448
else {
4549
console.log('Installing latest emulator.');

0 commit comments

Comments
 (0)