diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js index 6f20c192..61bd4494 100644 --- a/bin/lib/check_reqs.js +++ b/bin/lib/check_reqs.js @@ -64,23 +64,6 @@ module.exports.get_target = function() { } } -// Returns a promise. -module.exports.sdk_dir = function() { - var d = Q.defer(); - which('android', function(err, path) { - if (err) { - d.reject(new Error('ERROR: Cannot find Android SDK. android command not found.')); - } else { - var toolsDir = path.substring(0, path.lastIndexOf('/')); - if (toolsDir.substring(toolsDir.length-6) != "/tools") { - d.reject(new Error('ERROR: Cannot find Android SDK. android command not found in tools dir.')); - } - d.resolve(toolsDir.substring(0, toolsDir.length-6)); - } - }); - return d.promise; -}; - // Returns a promise. Called only by build and clean commands. module.exports.check_ant = function() { return tryCommand('ant -version', 'Failed to run "ant -version", make sure you have ant installed and added to your PATH.'); diff --git a/bin/lib/create.js b/bin/lib/create.js index d1f43e67..cc42f194 100755 --- a/bin/lib/create.js +++ b/bin/lib/create.js @@ -111,13 +111,6 @@ function copyScripts(projectPath) { shell.cp(path.join(ROOT, 'bin', 'lib', 'android_sdk_version.js'), path.join(projectPath, 'cordova', 'lib', 'android_sdk_version.js')); } -function copyGradleWrapper(sdkPath, projectPath) { - var wrapperDir = path.join(sdkPath, 'tools', 'templates','gradle','wrapper'); - shell.cp(path.join(wrapperDir, 'gradlew'), projectPath); - shell.cp(path.join(wrapperDir, 'gradlew.bat'), projectPath); - shell.cp('-r', path.join(wrapperDir, 'gradle'), projectPath); -} - /** * Test whether a package name is acceptable for use as an android project. * Returns a promise, fulfilled if the package name is acceptable; rejected @@ -225,16 +218,6 @@ exports.createProject = function(project_path, package_name, project_name, proje shell.cp('-r', path.join(project_template_dir, 'res'), project_path); shell.cp('-r', path.join(ROOT, 'framework', 'res', 'xml'), path.join(project_path, 'res')); - shell.cp('-f', path.join(project_template_dir, 'build.gradle'), project_path); - shell.cp('-f', path.join(project_template_dir, 'libraries.gradle'), project_path); - shell.cp('-f', path.join(project_template_dir, 'settings.gradle'), project_path); - check_reqs.sdk_dir().then(function(dir) { - console.log("Copying Gradle wrapper from " + dir); - copyGradleWrapper(dir, project_path); - }).catch(function(err) { - console.log("Cannot find Android SDK. Not installing Gradle wrapper."); - }); - // Manually create directories that would be empty within the template (since git doesn't track directories). shell.mkdir(path.join(project_path, 'libs')); diff --git a/bin/templates/cordova/lib/build.js b/bin/templates/cordova/lib/build.js index 1f0cd23f..80e2282b 100644 --- a/bin/templates/cordova/lib/build.js +++ b/bin/templates/cordova/lib/build.js @@ -51,6 +51,24 @@ function hasCustomRules() { return fs.existsSync(path.join(ROOT, 'custom_rules.xml')); } +// Copy the gradle wrapper files on each build so that: +// A) We don't require the Android SDK at project creation time, and +// B) So that they are always up-to-date. +function copyGradleWrapper() { + var projectPath = ROOT; + // check_reqs ensures that this is set. + var sdkDir = process.env['ANDROID_HOME']; + var wrapperDir = path.join(sdkDir, 'tools', 'templates', 'gradle', 'wrapper'); + if (process.platform == 'win32') { + shell.cp('-f', path.join(wrapperDir, 'gradlew.bat'), projectPath); + } else { + shell.cp('-f', path.join(wrapperDir, 'gradlew'), projectPath); + } + shell.rm('-rf', path.join(projectPath, 'gradle', 'wrapper')); + shell.mkdir('-p', path.join(projectPath, 'gradle')); + shell.cp('-r', path.join(wrapperDir, 'gradle', 'wrapper'), path.join(projectPath, 'gradle')); +} + module.exports.builders = { ant: { getArgs: function(cmd) { @@ -129,6 +147,7 @@ module.exports.builders = { var builder = this; var wrapper = path.join(ROOT, 'gradlew'); var args = builder.getArgs('build'); + copyGradleWrapper(); return Q().then(function() { return spawn(wrapper, args); }).then(function() {