Skip to content

Commit

Permalink
Merge branch 'master' into release/v2
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ychescale9 committed Mar 5, 2020
2 parents 2754675 + da846ad commit 6bb3965
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 155 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
api-level: [21, 23, 29]
api-level: [16, 21, 23, 29]
steps:
- name: checkout
uses: actions/checkout@v2
Expand All @@ -37,13 +37,14 @@ jobs:
uses: ./
with:
api-level: ${{ matrix.api-level }}
target: google_apis
target: default
arch: x86
profile: Nexus 6
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -camera-back none
disable-animations: true
working-directory: ./test-fixture/
script: |
echo $GITHUB_REPOSITORY
adb devices
./gradlew help
./gradlew connectedDebugAndroidTest
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## v2.5.0

* Added support for API 15-19 system images.
* Switched to the new SDK command-line tools which supports running `sdkmanager` and `avdmanager` with Java 9+.

## v2.4.0

* Added support for setting custom `working-directory` - e.g. `./android` if your root Gradle project is under the `./android` sub-directory within your repository.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ jobs:

| | **Required** | **Default** | **Description** |
|----------------------|--------------|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `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**. |
| `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**. |
| `target` | Optional | `default` | Target of the system image - `default` or `google_apis`. |
| `arch` | Optional | `x86` | CPU architecture of the system image - `x86` or `x86_64`. |
| `arch` | Optional | `x86` | CPU architecture of the system image - `x86` or `x86_64`. Note that `x86_64` image is only available for API 21+. |
| `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". |
| `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`. |
| `disable-animations` | Optional | `true` | Whether to disable animations - `true` or `false`. |
Expand Down
4 changes: 2 additions & 2 deletions __tests__/input-validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ describe('api-level validator tests', () => {

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

it('Validates successfully with valid api-level', () => {
const func1 = () => {
validator.checkApiLevel('21');
validator.checkApiLevel('15');
};
expect(func1).not.toThrow();

Expand Down
18 changes: 8 additions & 10 deletions lib/emulator-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const exec = __importStar(require("@actions/exec"));
const EMULATOR_BOOT_TIMEOUT_SECONDS = 300;
const AVD_MANAGER_PATH = `${process.env.ANDROID_HOME}/tools/bin/avdmanager`;
const ADB_PATH = `${process.env.ANDROID_HOME}/platform-tools/adb`;
/**
* Creates and launches a new AVD instance with the specified configurations.
*/
Expand All @@ -27,11 +25,11 @@ function launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disabl
// create a new AVD
if (profile.trim() !== '') {
console.log(`Creating AVD with custom profile ${profile}`);
yield exec.exec(`${AVD_MANAGER_PATH} create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`);
yield exec.exec(`avdmanager create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`);
}
else {
console.log(`Creating AVD without custom profile.`);
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}'"`);
yield exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n test --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`);
}
// start emulator
console.log('Starting emulator.');
Expand All @@ -46,13 +44,13 @@ function launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disabl
});
// wait for emulator to complete booting
yield waitForDevice();
yield exec.exec(`${ADB_PATH} shell input keyevent 82`);
yield exec.exec(`adb shell input keyevent 82`);
// disable animations
if (disableAnimations) {
console.log('Disabling animations.');
yield exec.exec(`${ADB_PATH} shell settings put global window_animation_scale 0.0`);
yield exec.exec(`${ADB_PATH} shell settings put global transition_animation_scale 0.0`);
yield exec.exec(`${ADB_PATH} shell settings put global animator_duration_scale 0.0`);
yield exec.exec(`adb shell settings put global window_animation_scale 0.0`);
yield exec.exec(`adb shell settings put global transition_animation_scale 0.0`);
yield exec.exec(`adb shell settings put global animator_duration_scale 0.0`);
}
});
}
Expand All @@ -63,7 +61,7 @@ exports.launchEmulator = launchEmulator;
function killEmulator() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield exec.exec(`${ADB_PATH} -s emulator-5554 emu kill`);
yield exec.exec(`adb -s emulator-5554 emu kill`);
}
catch (error) {
console.log(error.message);
Expand All @@ -83,7 +81,7 @@ function waitForDevice() {
while (!booted) {
try {
let result = '';
yield exec.exec(`${ADB_PATH} shell getprop sys.boot_completed`, [], {
yield exec.exec(`adb shell getprop sys.boot_completed`, [], {
listeners: {
stdout: (data) => {
result += data.toString();
Expand Down
2 changes: 1 addition & 1 deletion lib/input-validator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MIN_API_LEVEL = 21;
exports.MIN_API_LEVEL = 15;
exports.VALID_TARGETS = ['default', 'google_apis'];
exports.VALID_ARCHS = ['x86', 'x86_64'];
function checkApiLevel(apiLevel) {
Expand Down
60 changes: 0 additions & 60 deletions lib/java-version-manager.js

This file was deleted.

6 changes: 0 additions & 6 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const input_validator_1 = require("./input-validator");
const emulator_manager_1 = require("./emulator-manager");
const exec = __importStar(require("@actions/exec"));
const script_parser_1 = require("./script-parser");
const java_version_manager_1 = require("./java-version-manager");
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
Expand Down Expand Up @@ -73,9 +72,6 @@ function run() {
scripts.forEach((script) => __awaiter(this, void 0, void 0, function* () {
console.log(`${script}`);
}));
// use Java 8 for sdkmanager and avdmanager
const defaultJavaHome = yield java_version_manager_1.getCurrentJavaHome();
java_version_manager_1.setJavaHome(yield java_version_manager_1.getJavaHomeV8());
// install SDK
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, emulatorBuild);
try {
Expand All @@ -85,8 +81,6 @@ function run() {
catch (error) {
core.setFailed(error.message);
}
// use default JAVA_HOME for running custom script
java_version_manager_1.setJavaHome(defaultJavaHome);
// execute the custom script
try {
// move to custom working directory if set
Expand Down
16 changes: 12 additions & 4 deletions lib/sdk-installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
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';
/**
* 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 sdkmanagerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
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`);
// 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`);
console.log('Installing latest build tools, platform tools, and platform.');
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
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`);
Expand All @@ -35,10 +43,10 @@ function installAndroidSdk(apiLevel, target, arch, emulatorBuild) {
}
else {
console.log('Installing latest emulator.');
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install emulator > /dev/null"`);
yield exec.exec(`sh -c \\"sdkmanager --install emulator > /dev/null"`);
}
console.log('Installing system images.');
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
yield exec.exec(`sh -c \\"sdkmanager --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
});
}
exports.installAndroidSdk = installAndroidSdk;
18 changes: 8 additions & 10 deletions src/emulator-manager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as exec from '@actions/exec';

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

/**
* Creates and launches a new AVD instance with the specified configurations.
Expand All @@ -11,10 +9,10 @@ export async function launchEmulator(apiLevel: number, target: string, arch: str
// create a new AVD
if (profile.trim() !== '') {
console.log(`Creating AVD with custom profile ${profile}`);
await exec.exec(`${AVD_MANAGER_PATH} create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`);
await exec.exec(`avdmanager create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`);
} else {
console.log(`Creating AVD without custom profile.`);
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}'"`);
await exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n test --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`);
}

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

// wait for emulator to complete booting
await waitForDevice();
await exec.exec(`${ADB_PATH} shell input keyevent 82`);
await exec.exec(`adb shell input keyevent 82`);

// disable animations
if (disableAnimations) {
console.log('Disabling animations.');
await exec.exec(`${ADB_PATH} shell settings put global window_animation_scale 0.0`);
await exec.exec(`${ADB_PATH} shell settings put global transition_animation_scale 0.0`);
await exec.exec(`${ADB_PATH} shell settings put global animator_duration_scale 0.0`);
await exec.exec(`adb shell settings put global window_animation_scale 0.0`);
await exec.exec(`adb shell settings put global transition_animation_scale 0.0`);
await exec.exec(`adb shell settings put global animator_duration_scale 0.0`);
}
}

Expand All @@ -47,7 +45,7 @@ export async function launchEmulator(apiLevel: number, target: string, arch: str
*/
export async function killEmulator(): Promise<void> {
try {
await exec.exec(`${ADB_PATH} -s emulator-5554 emu kill`);
await exec.exec(`adb -s emulator-5554 emu kill`);
} catch (error) {
console.log(error.message);
}
Expand All @@ -64,7 +62,7 @@ async function waitForDevice(): Promise<void> {
while (!booted) {
try {
let result = '';
await exec.exec(`${ADB_PATH} shell getprop sys.boot_completed`, [], {
await exec.exec(`adb shell getprop sys.boot_completed`, [], {
listeners: {
stdout: (data: Buffer) => {
result += data.toString();
Expand Down
2 changes: 1 addition & 1 deletion src/input-validator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const MIN_API_LEVEL = 21;
export const MIN_API_LEVEL = 15;
export const VALID_TARGETS: Array<string> = ['default', 'google_apis'];
export const VALID_ARCHS: Array<string> = ['x86', 'x86_64'];

Expand Down
39 changes: 0 additions & 39 deletions src/java-version-manager.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { checkApiLevel, checkTarget, checkArch, checkDisableAnimations, checkEmu
import { launchEmulator, killEmulator } from './emulator-manager';
import * as exec from '@actions/exec';
import { parseScript } from './script-parser';
import { getCurrentJavaHome, getJavaHomeV8, setJavaHome } from './java-version-manager';

async function run() {
try {
Expand Down Expand Up @@ -66,10 +65,6 @@ async function run() {
console.log(`${script}`);
});

// use Java 8 for sdkmanager and avdmanager
const defaultJavaHome = await getCurrentJavaHome();
setJavaHome(await getJavaHomeV8());

// install SDK
await installAndroidSdk(apiLevel, target, arch, emulatorBuild);

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

// use default JAVA_HOME for running custom script
setJavaHome(defaultJavaHome);

// execute the custom script
try {
// move to custom working directory if set
Expand Down
Loading

0 comments on commit 6bb3965

Please sign in to comment.