diff --git a/bin/lib/create.js b/bin/lib/create.js index 0ca877c1..bd0e2f1d 100755 --- a/bin/lib/create.js +++ b/bin/lib/create.js @@ -87,6 +87,11 @@ function runAndroidUpdate(projectPath, target_api, shared) { return exec('android update project --subprojects --path "' + projectPath + '" --target ' + target_api + ' --library "' + path.relative(projectPath, targetFrameworkDir) + '"'); } +function copyAntRules(projectPath) { + var srcDir = path.join(ROOT, 'bin', 'templates', 'project'); + shell.cp('-f', path.join(srcDir, 'custom_rules.xml'), projectPath); +} + function copyScripts(projectPath) { var srcScriptsDir = path.join(ROOT, 'bin', 'templates', 'cordova'); var destScriptsDir = path.join(projectPath, 'cordova'); @@ -186,6 +191,7 @@ exports.createProject = function(project_path, package_name, project_name, proje shell.sed('-i', /__PACKAGE__/, package_name, manifest_path); shell.sed('-i', /__APILEVEL__/, target_api.split('-')[1], manifest_path); copyScripts(project_path); + copyAntRules(project_path); }); // Link it to local android install. return runAndroidUpdate(project_path, target_api, use_shared_project); @@ -209,6 +215,7 @@ exports.updateProject = function(projectPath) { var target_api = check_reqs.get_target(); copyJsAndLibrary(projectPath, false, null); copyScripts(projectPath); + copyAntRules(projectPath); removeDebuggableFromManifest(projectPath); return runAndroidUpdate(projectPath, target_api, false) .then(function() { diff --git a/bin/templates/cordova/lib/build.js b/bin/templates/cordova/lib/build.js index 5e8ce0a0..7e0df2f3 100644 --- a/bin/templates/cordova/lib/build.js +++ b/bin/templates/cordova/lib/build.js @@ -26,6 +26,19 @@ var shell = require('shelljs'), fs = require('fs'), ROOT = path.join(__dirname, '..', '..'); + +function hasCustomRules() { + return fs.existsSync(path.join(ROOT, 'custom_rules.xml')); +} +module.exports.getAntArgs = function(cmd) { + var args = [cmd, '-f', path.join(ROOT, 'build.xml')]; + // custom_rules.xml is required for incremental builds. + if (hasCustomRules()) { + args.push('-Dout.dir=ant-build', '-Dgen.absolute.dir=ant-gen'); + } + return args; +}; + /* * Builds the project with ant. * Returns a promise. @@ -33,7 +46,7 @@ var shell = require('shelljs'), module.exports.run = function(build_type) { //default build type build_type = typeof build_type !== 'undefined' ? build_type : "--debug"; - var args = ['debug', '-f', path.join(ROOT, 'build.xml'), '-Dout.dir=ant-build', '-Dgen.dir=ant-build/gen']; + var args = module.exports.getAntArgs('debug'); switch(build_type) { case '--debug' : break; @@ -46,7 +59,14 @@ module.exports.run = function(build_type) { default : return Q.reject('Build option \'' + build_type + '\' not recognized.'); } - return spawn('ant', args); + // Without our custom_rules.xml, we need to clean before building. + var ret = Q(); + if (!hasCustomRules()) { + ret = require('./clean').run(); + } + return ret.then(function() { + return spawn('ant', args); + }); } /* diff --git a/bin/templates/cordova/lib/clean.js b/bin/templates/cordova/lib/clean.js index f86cfb8e..0a2e0ce0 100644 --- a/bin/templates/cordova/lib/clean.js +++ b/bin/templates/cordova/lib/clean.js @@ -19,16 +19,16 @@ under the License. */ -var spawn = require('./spawn'), - path = require('path'), - ROOT = path.join(__dirname, '..', '..'); +var build = require('./build'), + spawn = require('./spawn'), + path = require('path'); /* * Cleans the project using ant * Returns a promise. */ module.exports.run = function() { - var args = ['clean', '-f', path.join(ROOT, 'build.xml'), '-Dout.dir=ant-build', '-Dgen.dir=ant-build/gen']; + var args = build.getAntArgs('clean'); return spawn('ant', args); } diff --git a/bin/templates/project/custom_rules.xml b/bin/templates/project/custom_rules.xml new file mode 100644 index 00000000..51434ac0 --- /dev/null +++ b/bin/templates/project/custom_rules.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + +