mirror of
https://github.com/reactivecircus/android-emulator-runner.git
synced 2026-08-31 17:49:33 +00:00
57 lines
3.6 KiB
JavaScript
57 lines
3.6 KiB
JavaScript
"use strict";
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
result["default"] = 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_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.');
|
|
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-${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.');
|
|
yield exec.exec(`sh -c \\"sdkmanager --install emulator > /dev/null"`);
|
|
}
|
|
console.log('Installing system images.');
|
|
yield exec.exec(`sh -c \\"sdkmanager --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
|
|
});
|
|
}
|
|
exports.installAndroidSdk = installAndroidSdk;
|