Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android)(8_1_X): Fixed incremental build issues introduced by [TIMOB-27043] in 8.1.0 #10958

Merged
merged 6 commits into from Jun 12, 2019
30 changes: 26 additions & 4 deletions android/cli/commands/_build.js
Expand Up @@ -1908,6 +1908,7 @@ AndroidBuilder.prototype.initialize = function initialize(next) {
this.buildBinClassesDir = path.join(this.buildBinDir, 'classes');
this.buildBinClassesDex = path.join(this.buildBinDir, 'dexfiles');
this.buildGenDir = path.join(this.buildDir, 'gen');
this.buildIncrementalDir = path.join(this.buildDir, 'incremental');
this.buildIntermediatesDir = path.join(this.buildDir, 'intermediates');
this.buildGenAppIdDir = path.join(this.buildGenDir, this.appid.split('.').join(path.sep));
this.buildResDir = path.join(this.buildDir, 'res');
Expand Down Expand Up @@ -2074,6 +2075,22 @@ AndroidBuilder.prototype.checkIfShouldForceRebuild = function checkIfShouldForce
return true;
}

// if sourceMaps changed, then we need to re-process all of the JS files
if (this.sourceMaps !== manifest.sourceMaps) {
this.logger.info(__('Forcing rebuild: JavaScript sourceMaps flag changed'));
this.logger.info(' ' + __('Was: %s', manifest.sourceMaps));
this.logger.info(' ' + __('Now: %s', this.sourceMaps));
return true;
}

// if transpile changed, then we need to re-process all of the JS files
if (this.transpile !== manifest.transpile) {
this.logger.info(__('Forcing rebuild: JavaScript transpile flag changed'));
this.logger.info(' ' + __('Was: %s', manifest.transpile));
this.logger.info(' ' + __('Now: %s', this.transpile));
return true;
}

// check if the titanium sdk paths are different
if (this.platformPath !== manifest.platformPath) {
this.logger.info(__('Forcing rebuild: Titanium SDK path changed since last build'));
Expand Down Expand Up @@ -2276,8 +2293,9 @@ AndroidBuilder.prototype.createBuildDirs = function createBuildDirs(next) {
// make directories if they don't already exist
let dir = this.buildAssetsDir;
if (this.forceRebuild) {
fs.emptyDirSync(this.buildIncrementalDir);
fs.emptyDirSync(dir);
this.unmarkBuildDirFiles(this.buildAssetsDir);
this.unmarkBuildDirFiles(dir);
} else {
fs.ensureDirSync(dir);
}
Expand Down Expand Up @@ -2669,15 +2687,15 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {
const from = jsFiles[relPath];
if (htmlJsFiles[relPath]) {
// this js file is referenced from an html file, so don't minify or encrypt
copyUnmodified.push(from);
copyUnmodified.push(relPath);
} else {
inputFiles.push(from);
}
});

const task = new ProcessJsTask({
inputFiles,
incrementalDirectory: path.join(this.buildDir, 'incremental', 'process-js'),
incrementalDirectory: path.join(this.buildIncrementalDir, 'process-js'),
logger: this.logger,
builder: this,
jsFiles: Object.keys(jsFiles).reduce((jsFilesInfo, relPath) => {
Expand Down Expand Up @@ -2814,8 +2832,10 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {
}

// write the encrypted JS bytes to the generated Java file
const assetCryptDest = path.join(this.buildGenAppIdDir, 'AssetCryptImpl.java');
this.unmarkBuildDirFile(assetCryptDest);
fs.writeFileSync(
path.join(this.buildGenAppIdDir, 'AssetCryptImpl.java'),
assetCryptDest,
ejs.render(fs.readFileSync(path.join(this.templatesDir, 'AssetCryptImpl.java')).toString(), {
appid: this.appid,
encryptedAssets: out
Expand Down Expand Up @@ -4602,6 +4622,8 @@ AndroidBuilder.prototype.writeBuildManifest = function writeBuildManifest(callba
skipJSMinification: !!this.cli.argv['skip-js-minify'],
mergeCustomAndroidManifest: this.config.get('android.mergeCustomAndroidManifest', true),
encryptJS: this.encryptJS,
sourceMaps: this.sourceMaps,
transpile: this.transpile,
minSDK: this.minSDK,
targetSDK: this.targetSDK,
propertiesHash: this.propertiesHash,
Expand Down
37 changes: 37 additions & 0 deletions tests/Resources/ti.ui.webview.addontest.js
@@ -0,0 +1,37 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* global Ti */
/* eslint no-unused-expressions: "off" */
'use strict';

describe('Titanium.UI.WebView', function () {
var win;

afterEach(function () {
if (win) {
win.close();
}
win = null;
});

// Verifies local HTML file can access local JS file and invoke an HTML "onload" callback.
it.windowsMissing('html-script-tag', function (finish) {
this.slow(3000);
this.timeout(5000);

Ti.App.addEventListener('ti.ui.webview.script.tag:onPageLoaded', function () {
finish();
});

win = Ti.UI.createWindow();
win.add(Ti.UI.createWebView({
url: 'ti.ui.webview.script.tag.html'
}));
win.open();
});
});
9 changes: 9 additions & 0 deletions tests/Resources/ti.ui.webview.script.tag.html
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<script src="ti.ui.webview.script.tag.js"></script>
</head>
<body onload="onPageLoaded();">
This verifies that a local HTML file can access a local JS file.
</body>
</html>
15 changes: 15 additions & 0 deletions tests/Resources/ti.ui.webview.script.tag.js
@@ -0,0 +1,15 @@
/*
* Axway Appcelerator Titanium Mobile
* Copyright (c) 2011-2019 by Axway Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* global Ti */
/* eslint no-unused-expressions: "off" */
'use strict';

// eslint-disable-next-line no-unused-vars
function onPageLoaded() {
Ti.App.fireEvent('ti.ui.webview.script.tag:onPageLoaded', {});
}