Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-15249
Browse files Browse the repository at this point in the history
  • Loading branch information
ssjsamir committed Jul 6, 2017
2 parents 9119fda + da10975 commit 86659b8
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 19 deletions.
16 changes: 9 additions & 7 deletions android/cli/commands/_buildModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ AndroidModuleBuilder.prototype.validate = function validate(logger, config, cli)
androidDetect(config, { packageJson: this.packageJson }, function (androidInfo) {
this.androidInfo = androidInfo;

if (!this.androidInfo.ndk.path) {
if (!this.androidInfo.ndk) {
logger.error(__('Unable to find a suitable installed Android NDK.') + '\n');
process.exit(1);
}
Expand Down Expand Up @@ -1804,10 +1804,10 @@ AndroidModuleBuilder.prototype.runModule = function (next) {
}

function runTiCommand(cmd, args, logger, callback) {
// when calling a Windows batch file, we need to escape ampersands in the command
if (process.platform == 'win32' && /\.bat$/.test(cmd)) {
args.unshift('/S', '/C', cmd.replace(/\&/g, '^&'));
cmd = 'cmd.exe';

// when calling on Windows, we need to escape ampersands in the command
if (process.platform == 'win32') {
cmd.replace(/\&/g, '^&');
}

var child = spawn(cmd, args);
Expand Down Expand Up @@ -1845,8 +1845,9 @@ AndroidModuleBuilder.prototype.runModule = function (next) {
this.logger.debug(__('Staging module project at %s', tmpDir.cyan));

runTiCommand(
'ti',
process.execPath,
[
process.argv[1],
'create',
'--id', this.manifest.moduleid,
'-n', this.manifest.name,
Expand Down Expand Up @@ -1893,8 +1894,9 @@ AndroidModuleBuilder.prototype.runModule = function (next) {
this.logger.debug(__('Running example project...', tmpDir.cyan));

runTiCommand(
'ti',
process.execPath,
[
process.argv[1],
'build',
'-p', 'android',
'-d', tmpProjectDir
Expand Down
102 changes: 101 additions & 1 deletion android/cli/hooks/aar-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ const LIBRARY_ORIGIN_PORJECT = 'Project';

exports.cliVersion = '>=3.2';

exports.init = function (logger, config, cli) {
exports.init = function (logger, config, cli, appc) {
cli.on('build.pre.compile', {
priority: 1100,
post: function(builder, callback) {
registerHyperloopCompatibilityFixes(cli, builder, appc, logger);
scanProjectAndStartTransform(builder, logger, callback);
}
});
Expand Down Expand Up @@ -445,3 +446,102 @@ class SimpleFileCache {
fs.writeFileSync(this.cachePathAndFilename, dataToWrite);
}
}

/**
* Hyperloop versions below 2.2.0 have their own AAR handling which we need to
* disable by hooking into the affected hooks and reverting the changes Hyperloop
* made.
*
* @param {Object} cli CLI instance
* @param {Object} builder Builder instance
* @param {Object} appc Appc node utilities
* @param {Object} logger Logger instance
*/
function registerHyperloopCompatibilityFixes(cli, builder, appc, logger) {
var hyperloopModule = null;
builder.nativeLibModules.some(function (module) {
if (module.id === 'hyperloop' && appc.version.lt(module.version, '2.2.0')) {
hyperloopModule = module;
return true;
}
});
if (hyperloopModule === null) {
return;
}

var hyperloopBuildPath = path.join(builder.projectDir, 'build/hyperloop/android');

cli.on('build.android.aapt', {
priority: 1100,
/**
* Remove parameters passed to AAPT which are not required anymore since 6.1.0
*
* @param {Object} data Hook data
* @param {Function} callback Callback function
*/
pre: function (data, callback) {
logger.trace('Cleaning AAPT options from changes made by Hyperloop');
var aaptOptions = data.args[1];
var extraPackagesIndex = aaptOptions.indexOf('--extra-packages') + 1;
if (extraPackagesIndex === -1) {
return callback();
}
var extraPackages = aaptOptions[extraPackagesIndex];
var parameterIndex = aaptOptions.indexOf('-S');
var packageNameRegex = /package="(.*)"/;
while (parameterIndex !== -1) {
var resourcePath = aaptOptions[parameterIndex + 1];
if (resourcePath.indexOf(hyperloopBuildPath) !== -1) {
var manifestPathAndFilename = path.join(resourcePath, '../AndroidManifest.xml');
if (fs.existsSync(manifestPathAndFilename)) {
var manifestContent = fs.readFileSync(manifestPathAndFilename).toString();
var packageNameMatch = manifestContent.match(packageNameRegex);
if (packageNameMatch !== null) {
var packageName = packageNameMatch[1];
extraPackages = extraPackages.split(':').filter(n => n !== packageName).join(':');
logger.trace('Removed package ' + packageName + ' from AAPT --extra-packages option');
}
}
aaptOptions.splice(parameterIndex, 2);
logger.trace('Removed AAPT -S resource path ' + resourcePath);
parameterIndex = aaptOptions.indexOf('-S', parameterIndex);
} else {
parameterIndex = aaptOptions.indexOf('-S', parameterIndex + 1);
}
}
aaptOptions[extraPackagesIndex] = extraPackages;
callback();
}
});


cli.on('build.android.dexer', {
priority: 1100,
/**
* Fixes repeated adding of the same JAR to the dexer to avoid crashing
* with a dreaded "already added" exception
*
* @param {Object} data Hook data
* @param {Function} callback Callback function
*/
pre: function (data, callback) {
logger.trace('Cleaning dexer paths from changes made by Hyperloop');
var builder = data.ctx;
var dexerOptions = data.args[1].slice(0, 6);
var dexerPaths = data.args[1].slice(6);
if (builder.androidLibraries.length > 0) {
var fixedDexerPaths = [];
dexerPaths.forEach(function (entryPathAndFilename) {
var isHyperloopExtractedAarPath = entryPathAndFilename.indexOf(hyperloopBuildPath) !== -1;
if (builder.isExternalAndroidLibraryAvailable(entryPathAndFilename) || isHyperloopExtractedAarPath) {
logger.trace('Removed ' + entryPathAndFilename + ' from dexer paths.');
} else {
fixedDexerPaths.push(entryPathAndFilename);
}
}, builder);
data.args[1] = dexerOptions.concat(fixedDexerPaths);
}
callback();
}
});
}
3 changes: 2 additions & 1 deletion build/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ Android.prototype.package = function (packager, next) {
},
// Copy over module resources
function (cb) {
fs.copy(DIST_ANDROID, ANDROID_MODULES, { filter: /\/android(\/titanium\-(.+)?\.(jar|res\.zip|respackage))?$/ }, cb);
var filterRegExp = new RegExp('\\' + path.sep + 'android(\\' + path.sep + 'titanium\-(.+)?\.(jar|res\.zip|respackage))?$');
fs.copy(DIST_ANDROID, ANDROID_MODULES, { filter: filterRegExp}, cb);
}
], next);
};
Expand Down
14 changes: 4 additions & 10 deletions build/scons-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var exec = require('child_process').exec,
path = require('path'),
async = require('async'),
program = require('commander'),
version = require('../package.json').version;
version = require('../package.json').version,
appc = require('node-appc');

program
.option('-v, --sdk-version [version]', 'Override the SDK version we report', process.env.PRODUCT_VERSION || version)
Expand All @@ -24,7 +25,7 @@ function install(versionTag, next) {
osName = os.platform();

if (osName === 'win32') {
return next('Unable to unzip files on Windows currently. FIXME!');
dest = path.join(process.env.ProgramData, 'Titanium');
}

if (osName === 'darwin') {
Expand All @@ -36,14 +37,7 @@ function install(versionTag, next) {
zipfile = path.join(__dirname, '..', 'dist', 'mobilesdk-' + versionTag + '-' + osName + '.zip');
console.log('Installing %s...', zipfile);

// TODO Combine with unzip method in packager.js?
// TODO Support unzipping on windows
exec('/usr/bin/unzip -q -o -d "' + dest + '" "' + zipfile + '"', function (err, stdout, stderr) {
if (err) {
return next(err);
}
return next();
});
appc.zip.unzip(zipfile, dest, { overwrite:true }, next);
}

install(versionTag, function (err) {
Expand Down

0 comments on commit 86659b8

Please sign in to comment.