From cc382753576b5253dab3baaa2e4269618e470260 Mon Sep 17 00:00:00 2001 From: Vilius Sutkus '89 Date: Wed, 3 Feb 2021 03:43:38 +0200 Subject: [PATCH] Un-whitespace ANDROID_SDK_ROOT sdkmanager doesn't like spaces in it's path. Move the whole SDK to a place without spaces. --- src/main.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main.ts b/src/main.ts index ab3bc59..0c35835 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,8 +16,7 @@ const COMMANDLINE_TOOLS_LIN_URL = `https://dl.google.com/android/repository/comm const HOME = os.homedir() const ANDROID_HOME_DIR = path.join(HOME, '.android') const ANDROID_HOME_SDK_DIR = path.join(ANDROID_HOME_DIR, 'sdk') -const ANDROID_SDK_ROOT = process.env['ANDROID_SDK_ROOT'] || ANDROID_HOME_SDK_DIR -const ANDROID_REPOSITORIES_CFG = path.join(ANDROID_SDK_ROOT, 'repositories.cfg') +let ANDROID_SDK_ROOT = process.env['ANDROID_SDK_ROOT'] || ANDROID_HOME_SDK_DIR function getSdkManagerPath(cmdToolsVersion: string): string { return path.join( @@ -89,8 +88,10 @@ async function callSdkManager(sdkManager: string, arg: string): Promise { async function installSdkManager(): Promise { fs.mkdirSync(ANDROID_SDK_ROOT, {recursive: true}) - // touch ~/.android/repositories.cfg - fs.closeSync(fs.openSync(ANDROID_REPOSITORIES_CFG, 'w')) + // touch $ANDROID_SDK_ROOT/repositories.cfg + fs.closeSync( + fs.openSync(path.join(ANDROID_SDK_ROOT, 'repositories.cfg'), 'w') + ) const sdkManager = findPreinstalledSdkManager() if (!sdkManager.isFound) { @@ -139,6 +140,24 @@ async function installSdkManager(): Promise { } async function run(): Promise { + if ('win16' === process.env['ImageOS']) { + if (-1 !== ANDROID_SDK_ROOT.indexOf(' ')) { + // On Windows2016, Android SDK is installed to Program Files, + // and it doesn't really work.. + // C:\windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Android\android-sdk\cmdline-tools\3.0\bin\sdkmanager.bat" --licenses" + // Error: Could not find or load main class Files + + const newSDKLocation = ANDROID_SDK_ROOT.replace(/\s/gi, '-') + core.debug(`moving ${ANDROID_SDK_ROOT} to ${newSDKLocation}`) + fs.mkdirSync(path.dirname(newSDKLocation), {recursive: true}) + + // intentionally using fs.renameSync, + // because it doesn't move across drives + fs.renameSync(ANDROID_SDK_ROOT, newSDKLocation) + ANDROID_SDK_ROOT = newSDKLocation + } + } + const sdkManager = await installSdkManager() core.debug(`sdkmanager installed to: ${sdkManager}`) await callSdkManager(sdkManager, '--licenses')