Fixing the android path tooling

This commit is contained in:
Drew Heavner committed 2019-11-08 17:12:56 -05:00
1 parent bd300686fa
commit cc14b0e221
3 files changed
+29 -12

No files matched your search

+14 -6
View File
@@ -18,26 +18,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
const exec = __importStar(require("@actions/exec")); const exec = __importStar(require("@actions/exec"));
const core = __importStar(require("@actions/core")); const core = __importStar(require("@actions/core"));
const io = __importStar(require("@actions/io")); const io = __importStar(require("@actions/io"));
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
function signApkFile(apkFile, signingKeyFile, alias, keyStorePassword, keyPassword) { function signApkFile(apkFile, signingKeyFile, alias, keyStorePassword, keyPassword) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.debug("Zipaligning APK file"); core.debug("Zipaligning APK file");
// Find zipalign executable // Find zipalign executable
const zipAlignPath = yield io.which('zipalign', true); const buildToolsVersion = process.env.BUILD_TOOLS_VERSION || '29.0.2';
core.debug(`Found 'zipalign' @ ${zipAlignPath}`); 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 // Align the apk file
const alignedApkFile = apkFile.replace('.apk', '-aligned.apk'); const alignedApkFile = apkFile.replace('.apk', '-aligned.apk');
yield exec.exec(`"${zipAlignPath}"`, [ yield exec.exec(`"${zipAlign}"`, [
'-v', '-p 4', '-v', '-p 4',
apkFile, apkFile,
alignedApkFile alignedApkFile
]); ]);
core.debug("Signing APK file"); core.debug("Signing APK file");
// find apksigner path // find apksigner path
const apkSignerPath = yield io.which('apksigner', true); const apkSigner = path.join(buildTools, 'apksigner');
core.debug(`Found 'apksigner' @ ${apkSignerPath}`); core.debug(`Found 'apksigner' @ ${apkSigner}`);
// apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk // apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk
const signedApkFile = apkFile.replace('.apk', '-signed.apk'); const signedApkFile = apkFile.replace('.apk', '-signed.apk');
yield exec.exec(`"${apkSignerPath}"`, [ yield exec.exec(`"${apkSigner}"`, [
'sign', 'sign',
'--ks', signingKeyFile, '--ks', signingKeyFile,
'--out', signedApkFile, '--out', signedApkFile,
+15 -6
View File
@@ -1,6 +1,8 @@
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as io from '@actions/io'; import * as io from '@actions/io';
import * as path from "path";
import * as fs from "fs";
export async function signApkFile( export async function signApkFile(
apkFile: string, apkFile: string,
@@ -13,12 +15,19 @@ export async function signApkFile(
core.debug("Zipaligning APK file"); core.debug("Zipaligning APK file");
// Find zipalign executable // Find zipalign executable
const zipAlignPath = await io.which('zipalign', true); const buildToolsVersion = process.env.BUILD_TOOLS_VERSION || '29.0.2';
core.debug(`Found 'zipalign' @ ${zipAlignPath}`); 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 // Align the apk file
const alignedApkFile = apkFile.replace('.apk', '-aligned.apk'); const alignedApkFile = apkFile.replace('.apk', '-aligned.apk');
await exec.exec(`"${zipAlignPath}"`, [ await exec.exec(`"${zipAlign}"`, [
'-v', '-p 4', '-v', '-p 4',
apkFile, apkFile,
alignedApkFile alignedApkFile
@@ -27,12 +36,12 @@ export async function signApkFile(
core.debug("Signing APK file"); core.debug("Signing APK file");
// find apksigner path // find apksigner path
const apkSignerPath = await io.which('apksigner', true); const apkSigner = path.join(buildTools, 'apksigner');
core.debug(`Found 'apksigner' @ ${apkSignerPath}`); core.debug(`Found 'apksigner' @ ${apkSigner}`);
// apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk // apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk
const signedApkFile = apkFile.replace('.apk', '-signed.apk'); const signedApkFile = apkFile.replace('.apk', '-signed.apk');
await exec.exec(`"${apkSignerPath}"`, [ await exec.exec(`"${apkSigner}"`, [
'sign', 'sign',
'--ks', signingKeyFile, '--ks', signingKeyFile,
'--out', signedApkFile, '--out', signedApkFile,
Regular → Executable
View File
File mode changed.