Skip to content

Commit d279995

Browse files
committed
Merge branch 'main' into release/v2
* main: Prepare for release 2.15.0. Change default cores to 2, add cores in workflow Add option to modify the number of cores
2 parents 08b092e + 838986e commit d279995

File tree

8 files changed

+27
-3
lines changed

8 files changed

+27
-3
lines changed

.github/workflows/workflow.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ jobs:
7171
target: ${{ matrix.target }}
7272
arch: x86
7373
profile: Nexus 6
74+
cores: 2
7475
sdcard-path-or-size: 100M
7576
avd-name: test
7677
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -camera-back none

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.15.0
4+
5+
* Added support for specifying the number of cores to use for the emulator - [#130](https://github.com/ReactiveCircus/android-emulator-runner/pull/130).
6+
37
## v2.14.3
48

59
* Support `macos-11.0` (Big Sur) runner - [#124](https://github.com/ReactiveCircus/android-emulator-runner/pull/124).

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ jobs:
9292
| `target` | Optional | `default` | Target of the system image - `default`, `google_apis` or `playstore`. |
9393
| `arch` | Optional | `x86` | CPU architecture of the system image - `x86` or `x86_64`. Note that `x86_64` image is only available for API 21+. |
9494
| `profile` | Optional | N/A | Hardware profile used for creating the AVD - e.g. `Nexus 6`. For a list of all profiles available, run `avdmanager list` and refer to the results under "Available Android Virtual Devices". |
95+
| `cores` | Optional | 2 | Number of cores to use for the emulator (`hw.cpu.ncore` in config.ini). |
9596
| `sdcard-path-or-size` | Optional | N/A | Path to the SD card image for this AVD or the size of a new SD card image to create for this AVD, in KB or MB, denoted with K or M. - e.g. `path/to/sdcard`, or `1000M`. |
9697
| `avd-name` | Optional | `test` | Custom AVD name used for creating the Android Virtual Device. |
9798
| `emulator-options` | Optional | See below | Command-line options used when launching the emulator (replacing all default options) - e.g. `-no-window -no-snapshot -camera-back emulated`. |

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ inputs:
1616
default: 'x86'
1717
profile:
1818
description: 'hardware profile used for creating the AVD - e.g. `Nexus 6`'
19+
cores:
20+
description: 'the number of cores to use for the emulator'
21+
default: 2
1922
sdcard-path-or-size:
2023
description: 'path to the SD card image for this AVD or the size of a new SD card image to create for this AVD, in KB or MB, denoted with K or M. - e.g. `path/to/sdcard`, or `1000M`'
2124
avd-name:

lib/emulator-manager.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ const EMULATOR_BOOT_TIMEOUT_SECONDS = 600;
3434
/**
3535
* Creates and launches a new AVD instance with the specified configurations.
3636
*/
37-
function launchEmulator(apiLevel, target, arch, profile, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations) {
37+
function launchEmulator(apiLevel, target, arch, profile, cores, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations) {
3838
return __awaiter(this, void 0, void 0, function* () {
3939
// create a new AVD
4040
const profileOption = profile.trim() !== '' ? `--device '${profile}'` : '';
4141
const sdcardPathOrSizeOption = sdcardPathOrSize.trim() !== '' ? `--sdcard '${sdcardPathOrSize}'` : '';
4242
console.log(`Creating AVD.`);
4343
yield exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n "${avdName}" --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}' ${profileOption} ${sdcardPathOrSizeOption}"`);
44+
if (cores) {
45+
yield exec.exec(`sh -c \\"printf 'hw.cpu.ncore=${cores}\n' >> ~/.android/avd/"${avdName}".avd"/config.ini`);
46+
}
4447
// start emulator
4548
console.log('Starting emulator.');
4649
// turn off hardware acceleration on Linux

lib/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ function run() {
6363
// Hardware profile used for creating the AVD
6464
const profile = core.getInput('profile');
6565
console.log(`Hardware profile: ${profile}`);
66+
// Number of cores to use for emulator
67+
const cores = core.getInput('cores');
68+
console.log(`Cores: ${cores}`);
6669
// SD card path or size used for creating the AVD
6770
const sdcardPathOrSize = core.getInput('sdcard-path-or-size');
6871
console.log(`SD card path or size: ${sdcardPathOrSize}`);
@@ -112,7 +115,7 @@ function run() {
112115
// install SDK
113116
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, emulatorBuild, ndkVersion, cmakeVersion);
114117
// launch an emulator
115-
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations);
118+
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, cores, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations);
116119
// execute the custom script
117120
try {
118121
// move to custom working directory if set

src/emulator-manager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export async function launchEmulator(
1010
target: string,
1111
arch: string,
1212
profile: string,
13+
cores: string,
1314
sdcardPathOrSize: string,
1415
avdName: string,
1516
emulatorOptions: string,
@@ -23,6 +24,10 @@ export async function launchEmulator(
2324
`sh -c \\"echo no | avdmanager create avd --force -n "${avdName}" --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}' ${profileOption} ${sdcardPathOrSizeOption}"`
2425
);
2526

27+
if (cores) {
28+
await exec.exec(`sh -c \\"printf 'hw.cpu.ncore=${cores}\n' >> ~/.android/avd/"${avdName}".avd"/config.ini`);
29+
}
30+
2631
// start emulator
2732
console.log('Starting emulator.');
2833

src/main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ async function run() {
3939
const profile = core.getInput('profile');
4040
console.log(`Hardware profile: ${profile}`);
4141

42+
// Number of cores to use for emulator
43+
const cores = core.getInput('cores');
44+
console.log(`Cores: ${cores}`);
45+
4246
// SD card path or size used for creating the AVD
4347
const sdcardPathOrSize = core.getInput('sdcard-path-or-size');
4448
console.log(`SD card path or size: ${sdcardPathOrSize}`);
@@ -98,7 +102,7 @@ async function run() {
98102
await installAndroidSdk(apiLevel, target, arch, emulatorBuild, ndkVersion, cmakeVersion);
99103

100104
// launch an emulator
101-
await launchEmulator(apiLevel, target, arch, profile, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations);
105+
await launchEmulator(apiLevel, target, arch, profile, cores, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations);
102106

103107
// execute the custom script
104108
try {

0 commit comments

Comments
 (0)