From 1ca5f70029729e1c378671886fea22a836dd176e Mon Sep 17 00:00:00 2001 From: Joshua Quick Date: Thu, 30 Apr 2020 11:09:46 -0700 Subject: [PATCH] fix(android)(9_0_X): production builds no longer copy AAB to distribution folder as of 9.0.1 (#11645) - Regression introduced in 9.0.1 by using newest Android gradle tool. * Google renamed built AAB file and Titanium failed to find the file. * AAB file was stilling be built, just not be copied to given destination folder. - Added APK and AAB file validation. Will now trigger build failure if files were not found. Fixes TIMOB-27852 --- android/cli/commands/_build.js | 10 +++++++++- android/cli/hooks/package.js | 34 +++++++++++++--------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/android/cli/commands/_build.js b/android/cli/commands/_build.js index 9936b71e998..96138cc83c3 100644 --- a/android/cli/commands/_build.js +++ b/android/cli/commands/_build.js @@ -3689,7 +3689,15 @@ AndroidBuilder.prototype.buildAppProject = async function buildAppProject() { // Set path to the app-bundle file that was built up above. // Our "package.js" event hook will later copy it to the developer's chosen destination directory. - this.aabFile = path.join(this.buildDir, 'app', 'build', 'outputs', 'bundle', 'release', 'app.aab'); + this.aabFile = path.join(this.buildDir, 'app', 'build', 'outputs', 'bundle', 'release', 'app-release.aab'); + } + + // Verify that we can find the above built file(s). + if (!await fs.exists(this.apkFile)) { + throw new Error(`Failed to find built APK file: ${this.apkFile}`); + } + if (this.aabFile && !await fs.exists(this.aabFile)) { + throw new Error(`Failed to find built AAB file: ${this.aabFile}`); } }; diff --git a/android/cli/hooks/package.js b/android/cli/hooks/package.js index f3df8f3f0f0..1a410045b21 100644 --- a/android/cli/hooks/package.js +++ b/android/cli/hooks/package.js @@ -24,13 +24,6 @@ exports.init = function (logger, config, cli) { return finished(); } - // Fetch a path to the built APK file. - let sourceFilePath = builder.apkFile; - if (!sourceFilePath || !fs.existsSync(sourceFilePath)) { - logger.error(__('No APK file to deploy, skipping')); - return finished(); - } - // Do not continue if developer did not provide a destination directory. const outputDir = builder.outputDir; if (!outputDir) { @@ -38,26 +31,25 @@ exports.init = function (logger, config, cli) { return finished(); } - // Copy built app file(s) to destination directory. - if (outputDir !== path.dirname(sourceFilePath)) { - // Create the destination directory. - fs.ensureDirSync(outputDir); + // Create the destination directory. + fs.ensureDirSync(outputDir); - // Copy built APK to destination. - let outputFilePath = path.join(outputDir, builder.tiapp.name + '.apk'); + // Copy built APK to destination, if available. + if (builder.apkFile && fs.existsSync(builder.apkFile)) { + const outputFilePath = path.join(outputDir, builder.tiapp.name + '.apk'); if (fs.existsSync(outputFilePath)) { fs.unlinkSync(outputFilePath); } - appc.fs.copyFileSync(sourceFilePath, outputFilePath, { logger: logger.debug }); + appc.fs.copyFileSync(builder.apkFile, outputFilePath, { logger: logger.debug }); + } - // Copy built app-bundle to destination, if available. - if (builder.aabFile && fs.existsSync(builder.aabFile)) { - outputFilePath = path.join(outputDir, builder.tiapp.name + '.aab'); - if (fs.existsSync(outputFilePath)) { - fs.unlinkSync(outputFilePath); - } - appc.fs.copyFileSync(builder.aabFile, outputFilePath, { logger: logger.debug }); + // Copy built app-bundle to destination, if available. + if (builder.aabFile && fs.existsSync(builder.aabFile)) { + const outputFilePath = path.join(outputDir, builder.tiapp.name + '.aab'); + if (fs.existsSync(outputFilePath)) { + fs.unlinkSync(outputFilePath); } + appc.fs.copyFileSync(builder.aabFile, outputFilePath, { logger: logger.debug }); } logger.info(__('Packaging complete'));