From cc14b0e221347489e0ae09b831e64d6490824464 Mon Sep 17 00:00:00 2001 From: Drew Heavner Date: Fri, 8 Nov 2019 17:12:56 -0500 Subject: [PATCH] Fixing the android path tooling --- lib/signing.js | 20 ++++++++++++++------ src/signing.ts | 21 +++++++++++++++------ update_release.sh | 0 3 files changed, 29 insertions(+), 12 deletions(-) mode change 100644 => 100755 update_release.sh diff --git a/lib/signing.js b/lib/signing.js index 991897af..a293a57d 100644 --- a/lib/signing.js +++ b/lib/signing.js @@ -18,26 +18,34 @@ Object.defineProperty(exports, "__esModule", { value: true }); const exec = __importStar(require("@actions/exec")); const core = __importStar(require("@actions/core")); const io = __importStar(require("@actions/io")); +const path = __importStar(require("path")); +const fs = __importStar(require("fs")); function signApkFile(apkFile, signingKeyFile, alias, keyStorePassword, keyPassword) { return __awaiter(this, void 0, void 0, function* () { core.debug("Zipaligning APK file"); // Find zipalign executable - const zipAlignPath = yield io.which('zipalign', true); - core.debug(`Found 'zipalign' @ ${zipAlignPath}`); + const buildToolsVersion = process.env.BUILD_TOOLS_VERSION || '29.0.2'; + const androidHome = process.env.ANDROID_HOME; + const buildTools = path.join(androidHome, `build-tools/${buildToolsVersion}`); + if (!fs.existsSync(buildTools)) { + core.error(`Couldnt find the Android build tools @ ${buildTools}`); + } + const zipAlign = path.join(buildTools, 'zipalign'); + core.debug(`Found 'zipalign' @ ${zipAlign}`); // Align the apk file const alignedApkFile = apkFile.replace('.apk', '-aligned.apk'); - yield exec.exec(`"${zipAlignPath}"`, [ + yield exec.exec(`"${zipAlign}"`, [ '-v', '-p 4', apkFile, alignedApkFile ]); core.debug("Signing APK file"); // find apksigner path - const apkSignerPath = yield io.which('apksigner', true); - core.debug(`Found 'apksigner' @ ${apkSignerPath}`); + const apkSigner = path.join(buildTools, 'apksigner'); + core.debug(`Found 'apksigner' @ ${apkSigner}`); // apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk const signedApkFile = apkFile.replace('.apk', '-signed.apk'); - yield exec.exec(`"${apkSignerPath}"`, [ + yield exec.exec(`"${apkSigner}"`, [ 'sign', '--ks', signingKeyFile, '--out', signedApkFile, diff --git a/src/signing.ts b/src/signing.ts index 2cd7bebe..d47452c8 100644 --- a/src/signing.ts +++ b/src/signing.ts @@ -1,6 +1,8 @@ import * as exec from '@actions/exec'; import * as core from '@actions/core'; import * as io from '@actions/io'; +import * as path from "path"; +import * as fs from "fs"; export async function signApkFile( apkFile: string, @@ -13,12 +15,19 @@ export async function signApkFile( core.debug("Zipaligning APK file"); // Find zipalign executable - const zipAlignPath = await io.which('zipalign', true); - core.debug(`Found 'zipalign' @ ${zipAlignPath}`); + const buildToolsVersion = process.env.BUILD_TOOLS_VERSION || '29.0.2'; + const androidHome = process.env.ANDROID_HOME; + const buildTools = path.join(androidHome!, `build-tools/${buildToolsVersion}`); + if (!fs.existsSync(buildTools)) { + core.error(`Couldnt find the Android build tools @ ${buildTools}`) + } + + const zipAlign = path.join(buildTools, 'zipalign'); + core.debug(`Found 'zipalign' @ ${zipAlign}`); // Align the apk file const alignedApkFile = apkFile.replace('.apk', '-aligned.apk'); - await exec.exec(`"${zipAlignPath}"`, [ + await exec.exec(`"${zipAlign}"`, [ '-v', '-p 4', apkFile, alignedApkFile @@ -27,12 +36,12 @@ export async function signApkFile( core.debug("Signing APK file"); // find apksigner path - const apkSignerPath = await io.which('apksigner', true); - core.debug(`Found 'apksigner' @ ${apkSignerPath}`); + const apkSigner = path.join(buildTools, 'apksigner'); + core.debug(`Found 'apksigner' @ ${apkSigner}`); // apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk const signedApkFile = apkFile.replace('.apk', '-signed.apk'); - await exec.exec(`"${apkSignerPath}"`, [ + await exec.exec(`"${apkSigner}"`, [ 'sign', '--ks', signingKeyFile, '--out', signedApkFile, diff --git a/update_release.sh b/update_release.sh old mode 100644 new mode 100755