diff --git a/lib/sdk-installer.js b/lib/sdk-installer.js index feb6eb266..7931e7f61 100644 --- a/lib/sdk-installer.js +++ b/lib/sdk-installer.js @@ -39,7 +39,7 @@ const io = __importStar(require("@actions/io")); const tc = __importStar(require("@actions/tool-cache")); const fs = __importStar(require("fs")); const BUILD_TOOLS_VERSION = '35.0.0'; -// SDK command-line tools 16.0 +const CMDLINE_TOOLS_VERSION = '16.0'; // the downloads immediately below should correspond to this version const CMDLINE_TOOLS_URL_MAC = 'https://dl.google.com/android/repository/commandlinetools-mac-12266719_latest.zip'; const CMDLINE_TOOLS_URL_LINUX = 'https://dl.google.com/android/repository/commandlinetools-linux-12266719_latest.zip'; /** @@ -58,7 +58,18 @@ function installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndk yield exec.exec(`sh -c \\"sudo chown $USER:$USER ${process.env.ANDROID_HOME}/build-tools/${BUILD_TOOLS_VERSION} -R`); } const cmdlineToolsPath = `${process.env.ANDROID_HOME}/cmdline-tools`; - if (!fs.existsSync(cmdlineToolsPath)) { + // it may happen that cmdlineToolsPath exists, but is older than desired + if (fs.existsSync(cmdlineToolsPath)) { + const cmdlineToolsVer = (yield exec.getExecOutput(`sh -c "${cmdlineToolsPath}/latest/bin/sdkmanager --version"`)).stdout.trim(); + if (!cmdlineToolsVer.includes(CMDLINE_TOOLS_VERSION)) { + console.log(`latest cmdline-tools is version ${cmdlineToolsVer} instead of ${CMDLINE_TOOLS_VERSION}. Removing.`); + yield exec.exec(`sh -c \\"rm -fr ${cmdlineToolsPath}/latest"`); + } + else { + console.log(`latest cmdline-tools is expected version ${CMDLINE_TOOLS_VERSION}: "${cmdlineToolsVer}"`); + } + } + if (!fs.existsSync(`${cmdlineToolsPath}/latest`)) { console.log('Installing new cmdline-tools.'); const sdkUrl = isOnMac ? CMDLINE_TOOLS_URL_MAC : CMDLINE_TOOLS_URL_LINUX; const downloadPath = yield tc.downloadTool(sdkUrl); diff --git a/src/sdk-installer.ts b/src/sdk-installer.ts index 5c7a0f2c7..97ac2f656 100644 --- a/src/sdk-installer.ts +++ b/src/sdk-installer.ts @@ -5,7 +5,7 @@ import * as tc from '@actions/tool-cache'; import * as fs from 'fs'; const BUILD_TOOLS_VERSION = '35.0.0'; -// SDK command-line tools 16.0 +const CMDLINE_TOOLS_VERSION = '16.0'; // the downloads immediately below should correspond to this version const CMDLINE_TOOLS_URL_MAC = 'https://dl.google.com/android/repository/commandlinetools-mac-12266719_latest.zip'; const CMDLINE_TOOLS_URL_LINUX = 'https://dl.google.com/android/repository/commandlinetools-linux-12266719_latest.zip'; @@ -26,7 +26,19 @@ export async function installAndroidSdk(apiLevel: string, target: string, arch: } const cmdlineToolsPath = `${process.env.ANDROID_HOME}/cmdline-tools`; - if (!fs.existsSync(cmdlineToolsPath)) { + + // it may happen that cmdlineToolsPath exists, but is older than desired + if (fs.existsSync(cmdlineToolsPath)) { + const cmdlineToolsVer = (await exec.getExecOutput(`sh -c "${cmdlineToolsPath}/latest/bin/sdkmanager --version"`)).stdout.trim(); + if (!cmdlineToolsVer.includes(CMDLINE_TOOLS_VERSION)) { + console.log(`latest cmdline-tools is version ${cmdlineToolsVer} instead of ${CMDLINE_TOOLS_VERSION}. Removing.`); + await exec.exec(`sh -c \\"rm -fr ${cmdlineToolsPath}/latest"`); + } else { + console.log(`latest cmdline-tools is expected version ${CMDLINE_TOOLS_VERSION}: "${cmdlineToolsVer}"`); + } + } + + if (!fs.existsSync(`${cmdlineToolsPath}/latest`)) { console.log('Installing new cmdline-tools.'); const sdkUrl = isOnMac ? CMDLINE_TOOLS_URL_MAC : CMDLINE_TOOLS_URL_LINUX; const downloadPath = await tc.downloadTool(sdkUrl);