Skip to content

Commit

Permalink
fix(android)(9_0_X): production builds no longer copy AAB to distribu…
Browse files Browse the repository at this point in the history
…tion 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
  • Loading branch information
jquick-axway committed Apr 30, 2020
1 parent 7545627 commit 1ca5f70
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
10 changes: 9 additions & 1 deletion android/cli/commands/_build.js
Expand Up @@ -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}`);
}
};

Expand Down
34 changes: 13 additions & 21 deletions android/cli/hooks/package.js
Expand Up @@ -24,40 +24,32 @@ 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) {
logger.error(__('Packaging output directory path cannot be empty.'));
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'));
Expand Down

0 comments on commit 1ca5f70

Please sign in to comment.