From 727ef87eea2b9ec5b5613e6f68bbcdec966eeead Mon Sep 17 00:00:00 2001 From: Joshua Quick Date: Fri, 17 Apr 2020 13:41:39 -0700 Subject: [PATCH 1/2] fix(android): production builds don't copy AAB to distribution folder - 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. --- android/cli/commands/_build.js | 12 +++++++++++- android/cli/hooks/package.js | 34 +++++++++++++--------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/android/cli/commands/_build.js b/android/cli/commands/_build.js index 9936b71e998..4ab7e1f10d8 100644 --- a/android/cli/commands/_build.js +++ b/android/cli/commands/_build.js @@ -3689,7 +3689,17 @@ 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)) { + this.logger.error(`Failed to find built APK file: ${this.apkFile}`); + process.exit(1); + } + if (this.aabFile && !await fs.exists(this.aabFile)) { + this.logger.error(`Failed to find built AAB file: ${this.aabFile}`); + process.exit(1); } }; 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')); From a09d24d36419a7ee862d276535ea65217d6df943 Mon Sep 17 00:00:00 2001 From: Joshua Quick Date: Tue, 28 Apr 2020 15:59:28 -0700 Subject: [PATCH 2/2] chore(android): updated TIMOB-27852 based on feedback --- android/cli/commands/_build.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/android/cli/commands/_build.js b/android/cli/commands/_build.js index 4ab7e1f10d8..96138cc83c3 100644 --- a/android/cli/commands/_build.js +++ b/android/cli/commands/_build.js @@ -3694,12 +3694,10 @@ AndroidBuilder.prototype.buildAppProject = async function buildAppProject() { // Verify that we can find the above built file(s). if (!await fs.exists(this.apkFile)) { - this.logger.error(`Failed to find built APK file: ${this.apkFile}`); - process.exit(1); + throw new Error(`Failed to find built APK file: ${this.apkFile}`); } if (this.aabFile && !await fs.exists(this.aabFile)) { - this.logger.error(`Failed to find built AAB file: ${this.aabFile}`); - process.exit(1); + throw new Error(`Failed to find built AAB file: ${this.aabFile}`); } };