Skip to content

Commit 6bb3965

Browse files
committed
Merge branch 'master' into release/v2
* master: Prepare for release 2.5.0. Add support for API 15-19 system images. Use new cmdline-tools with support for running sdkmanager and avdmanager with Java 8+. Update test-fixture dependencies. Drop minSdkVersion to 15. Update to AGP 3.6.0 and Gradle 6.2.1 for test-fixture project.
2 parents 2754675 + da846ad commit 6bb3965

17 files changed

+62
-155
lines changed

.github/workflows/workflow.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
timeout-minutes: 10
1414
strategy:
1515
matrix:
16-
api-level: [21, 23, 29]
16+
api-level: [16, 21, 23, 29]
1717
steps:
1818
- name: checkout
1919
uses: actions/checkout@v2
@@ -37,13 +37,14 @@ jobs:
3737
uses: ./
3838
with:
3939
api-level: ${{ matrix.api-level }}
40-
target: google_apis
40+
target: default
4141
arch: x86
4242
profile: Nexus 6
4343
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -camera-back none
4444
disable-animations: true
4545
working-directory: ./test-fixture/
4646
script: |
4747
echo $GITHUB_REPOSITORY
48+
adb devices
4849
./gradlew help
4950
./gradlew connectedDebugAndroidTest

CHANGELOG.md

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

3+
## v2.5.0
4+
5+
* Added support for API 15-19 system images.
6+
* Switched to the new SDK command-line tools which supports running `sdkmanager` and `avdmanager` with Java 9+.
7+
38
## v2.4.0
49

510
* Added support for setting custom `working-directory` - e.g. `./android` if your root Gradle project is under the `./android` sub-directory within your repository.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ jobs:
6969

7070
| | **Required** | **Default** | **Description** |
7171
|----------------------|--------------|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
72-
| `api-level` | Required | N/A | API level of the platform system image - e.g. 23 for Android Marshmallow, 29 for Android 10. **Minimum API level supported is 21**. |
72+
| `api-level` | Required | N/A | API level of the platform system image - e.g. 23 for Android Marshmallow, 29 for Android 10. **Minimum API level supported is 15**. |
7373
| `target` | Optional | `default` | Target of the system image - `default` or `google_apis`. |
74-
| `arch` | Optional | `x86` | CPU architecture of the system image - `x86` or `x86_64`. |
74+
| `arch` | Optional | `x86` | CPU architecture of the system image - `x86` or `x86_64`. Note that `x86_64` image is only available for API 21+. |
7575
| `profile` | Optional | N/A | Hardware profile used for creating the AVD - e.g. `Nexus 6`. For a list of all profiles available, run `$ANDROID_HOME/tools/bin/avdmanager list` and refer to the results under "Available Android Virtual Devices". |
7676
| `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`. |
7777
| `disable-animations` | Optional | `true` | Whether to disable animations - `true` or `false`. |

__tests__/input-validator.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ describe('api-level validator tests', () => {
1717

1818
it('Throws if api-level is lower than min API supported', () => {
1919
const func = () => {
20-
validator.checkApiLevel('20');
20+
validator.checkApiLevel('14');
2121
};
2222
expect(func).toThrowError(`Minimum API level supported is ${validator.MIN_API_LEVEL}.`);
2323
});
2424

2525
it('Validates successfully with valid api-level', () => {
2626
const func1 = () => {
27-
validator.checkApiLevel('21');
27+
validator.checkApiLevel('15');
2828
};
2929
expect(func1).not.toThrow();
3030

lib/emulator-manager.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
1717
Object.defineProperty(exports, "__esModule", { value: true });
1818
const exec = __importStar(require("@actions/exec"));
1919
const EMULATOR_BOOT_TIMEOUT_SECONDS = 300;
20-
const AVD_MANAGER_PATH = `${process.env.ANDROID_HOME}/tools/bin/avdmanager`;
21-
const ADB_PATH = `${process.env.ANDROID_HOME}/platform-tools/adb`;
2220
/**
2321
* Creates and launches a new AVD instance with the specified configurations.
2422
*/
@@ -27,11 +25,11 @@ function launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disabl
2725
// create a new AVD
2826
if (profile.trim() !== '') {
2927
console.log(`Creating AVD with custom profile ${profile}`);
30-
yield exec.exec(`${AVD_MANAGER_PATH} create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`);
28+
yield exec.exec(`avdmanager create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`);
3129
}
3230
else {
3331
console.log(`Creating AVD without custom profile.`);
34-
yield exec.exec(`sh -c \\"echo no | ${AVD_MANAGER_PATH} create avd --force -n test --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`);
32+
yield exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n test --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`);
3533
}
3634
// start emulator
3735
console.log('Starting emulator.');
@@ -46,13 +44,13 @@ function launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disabl
4644
});
4745
// wait for emulator to complete booting
4846
yield waitForDevice();
49-
yield exec.exec(`${ADB_PATH} shell input keyevent 82`);
47+
yield exec.exec(`adb shell input keyevent 82`);
5048
// disable animations
5149
if (disableAnimations) {
5250
console.log('Disabling animations.');
53-
yield exec.exec(`${ADB_PATH} shell settings put global window_animation_scale 0.0`);
54-
yield exec.exec(`${ADB_PATH} shell settings put global transition_animation_scale 0.0`);
55-
yield exec.exec(`${ADB_PATH} shell settings put global animator_duration_scale 0.0`);
51+
yield exec.exec(`adb shell settings put global window_animation_scale 0.0`);
52+
yield exec.exec(`adb shell settings put global transition_animation_scale 0.0`);
53+
yield exec.exec(`adb shell settings put global animator_duration_scale 0.0`);
5654
}
5755
});
5856
}
@@ -63,7 +61,7 @@ exports.launchEmulator = launchEmulator;
6361
function killEmulator() {
6462
return __awaiter(this, void 0, void 0, function* () {
6563
try {
66-
yield exec.exec(`${ADB_PATH} -s emulator-5554 emu kill`);
64+
yield exec.exec(`adb -s emulator-5554 emu kill`);
6765
}
6866
catch (error) {
6967
console.log(error.message);
@@ -83,7 +81,7 @@ function waitForDevice() {
8381
while (!booted) {
8482
try {
8583
let result = '';
86-
yield exec.exec(`${ADB_PATH} shell getprop sys.boot_completed`, [], {
84+
yield exec.exec(`adb shell getprop sys.boot_completed`, [], {
8785
listeners: {
8886
stdout: (data) => {
8987
result += data.toString();

lib/input-validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.MIN_API_LEVEL = 21;
3+
exports.MIN_API_LEVEL = 15;
44
exports.VALID_TARGETS = ['default', 'google_apis'];
55
exports.VALID_ARCHS = ['x86', 'x86_64'];
66
function checkApiLevel(apiLevel) {

lib/java-version-manager.js

Lines changed: 0 additions & 60 deletions
This file was deleted.

lib/main.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const input_validator_1 = require("./input-validator");
2121
const emulator_manager_1 = require("./emulator-manager");
2222
const exec = __importStar(require("@actions/exec"));
2323
const script_parser_1 = require("./script-parser");
24-
const java_version_manager_1 = require("./java-version-manager");
2524
function run() {
2625
return __awaiter(this, void 0, void 0, function* () {
2726
try {
@@ -73,9 +72,6 @@ function run() {
7372
scripts.forEach((script) => __awaiter(this, void 0, void 0, function* () {
7473
console.log(`${script}`);
7574
}));
76-
// use Java 8 for sdkmanager and avdmanager
77-
const defaultJavaHome = yield java_version_manager_1.getCurrentJavaHome();
78-
java_version_manager_1.setJavaHome(yield java_version_manager_1.getJavaHomeV8());
7975
// install SDK
8076
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, emulatorBuild);
8177
try {
@@ -85,8 +81,6 @@ function run() {
8581
catch (error) {
8682
core.setFailed(error.message);
8783
}
88-
// use default JAVA_HOME for running custom script
89-
java_version_manager_1.setJavaHome(defaultJavaHome);
9084
// execute the custom script
9185
try {
9286
// move to custom working directory if set

lib/sdk-installer.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,25 @@ var __importStar = (this && this.__importStar) || function (mod) {
1515
return result;
1616
};
1717
Object.defineProperty(exports, "__esModule", { value: true });
18+
const core = __importStar(require("@actions/core"));
1819
const exec = __importStar(require("@actions/exec"));
1920
const BUILD_TOOLS_VERSION = '29.0.3';
21+
const CMDLINE_TOOLS_URL = 'https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip';
2022
/**
2123
* Installs & updates the Android SDK for the macOS platform, including SDK platform for the chosen API level, latest build tools, platform tools, Android Emulator,
2224
* and the system image for the chosen API level, CPU arch, and target.
2325
*/
2426
function installAndroidSdk(apiLevel, target, arch, emulatorBuild) {
2527
return __awaiter(this, void 0, void 0, function* () {
26-
const sdkmanagerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
28+
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`);
33+
// add paths for commandline-tools and platform-tools
34+
core.addPath(`${process.env.ANDROID_HOME}/cmdline-tools/tools:${process.env.ANDROID_HOME}/cmdline-tools/tools/bin:${process.env.ANDROID_HOME}/platform-tools`);
2735
console.log('Installing latest build tools, platform tools, and platform.');
28-
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
36+
yield exec.exec(`sh -c \\"sdkmanager --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
2937
if (emulatorBuild) {
3038
console.log(`Installing emulator build ${emulatorBuild}.`);
3139
yield exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-darwin-${emulatorBuild}.zip`);
@@ -35,10 +43,10 @@ function installAndroidSdk(apiLevel, target, arch, emulatorBuild) {
3543
}
3644
else {
3745
console.log('Installing latest emulator.');
38-
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install emulator > /dev/null"`);
46+
yield exec.exec(`sh -c \\"sdkmanager --install emulator > /dev/null"`);
3947
}
4048
console.log('Installing system images.');
41-
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
49+
yield exec.exec(`sh -c \\"sdkmanager --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
4250
});
4351
}
4452
exports.installAndroidSdk = installAndroidSdk;

src/emulator-manager.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as exec from '@actions/exec';
22

33
const EMULATOR_BOOT_TIMEOUT_SECONDS = 300;
4-
const AVD_MANAGER_PATH = `${process.env.ANDROID_HOME}/tools/bin/avdmanager`;
5-
const ADB_PATH = `${process.env.ANDROID_HOME}/platform-tools/adb`;
64

75
/**
86
* Creates and launches a new AVD instance with the specified configurations.
@@ -11,10 +9,10 @@ export async function launchEmulator(apiLevel: number, target: string, arch: str
119
// create a new AVD
1210
if (profile.trim() !== '') {
1311
console.log(`Creating AVD with custom profile ${profile}`);
14-
await exec.exec(`${AVD_MANAGER_PATH} create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`);
12+
await exec.exec(`avdmanager create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`);
1513
} else {
1614
console.log(`Creating AVD without custom profile.`);
17-
await exec.exec(`sh -c \\"echo no | ${AVD_MANAGER_PATH} create avd --force -n test --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`);
15+
await exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n test --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`);
1816
}
1917

2018
// start emulator
@@ -31,14 +29,14 @@ export async function launchEmulator(apiLevel: number, target: string, arch: str
3129

3230
// wait for emulator to complete booting
3331
await waitForDevice();
34-
await exec.exec(`${ADB_PATH} shell input keyevent 82`);
32+
await exec.exec(`adb shell input keyevent 82`);
3533

3634
// disable animations
3735
if (disableAnimations) {
3836
console.log('Disabling animations.');
39-
await exec.exec(`${ADB_PATH} shell settings put global window_animation_scale 0.0`);
40-
await exec.exec(`${ADB_PATH} shell settings put global transition_animation_scale 0.0`);
41-
await exec.exec(`${ADB_PATH} shell settings put global animator_duration_scale 0.0`);
37+
await exec.exec(`adb shell settings put global window_animation_scale 0.0`);
38+
await exec.exec(`adb shell settings put global transition_animation_scale 0.0`);
39+
await exec.exec(`adb shell settings put global animator_duration_scale 0.0`);
4240
}
4341
}
4442

@@ -47,7 +45,7 @@ export async function launchEmulator(apiLevel: number, target: string, arch: str
4745
*/
4846
export async function killEmulator(): Promise<void> {
4947
try {
50-
await exec.exec(`${ADB_PATH} -s emulator-5554 emu kill`);
48+
await exec.exec(`adb -s emulator-5554 emu kill`);
5149
} catch (error) {
5250
console.log(error.message);
5351
}
@@ -64,7 +62,7 @@ async function waitForDevice(): Promise<void> {
6462
while (!booted) {
6563
try {
6664
let result = '';
67-
await exec.exec(`${ADB_PATH} shell getprop sys.boot_completed`, [], {
65+
await exec.exec(`adb shell getprop sys.boot_completed`, [], {
6866
listeners: {
6967
stdout: (data: Buffer) => {
7068
result += data.toString();

src/input-validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const MIN_API_LEVEL = 21;
1+
export const MIN_API_LEVEL = 15;
22
export const VALID_TARGETS: Array<string> = ['default', 'google_apis'];
33
export const VALID_ARCHS: Array<string> = ['x86', 'x86_64'];
44

src/java-version-manager.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/main.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { checkApiLevel, checkTarget, checkArch, checkDisableAnimations, checkEmu
44
import { launchEmulator, killEmulator } from './emulator-manager';
55
import * as exec from '@actions/exec';
66
import { parseScript } from './script-parser';
7-
import { getCurrentJavaHome, getJavaHomeV8, setJavaHome } from './java-version-manager';
87

98
async function run() {
109
try {
@@ -66,10 +65,6 @@ async function run() {
6665
console.log(`${script}`);
6766
});
6867

69-
// use Java 8 for sdkmanager and avdmanager
70-
const defaultJavaHome = await getCurrentJavaHome();
71-
setJavaHome(await getJavaHomeV8());
72-
7368
// install SDK
7469
await installAndroidSdk(apiLevel, target, arch, emulatorBuild);
7570

@@ -80,9 +75,6 @@ async function run() {
8075
core.setFailed(error.message);
8176
}
8277

83-
// use default JAVA_HOME for running custom script
84-
setJavaHome(defaultJavaHome);
85-
8678
// execute the custom script
8779
try {
8880
// move to custom working directory if set

0 commit comments

Comments
 (0)