mirror of
https://github.com/apache/cordova-android.git
synced 2025-04-24 10:22:21 +08:00
CB-3445 Copy gradle wrapper in build instead of create
This should play nicer with updates to the android SDK.
This commit is contained in:
parent
36eab713a1
commit
ca8bb75b40
@ -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.
|
// Returns a promise. Called only by build and clean commands.
|
||||||
module.exports.check_ant = function() {
|
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.');
|
return tryCommand('ant -version', 'Failed to run "ant -version", make sure you have ant installed and added to your PATH.');
|
||||||
|
@ -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'));
|
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.
|
* Test whether a package name is acceptable for use as an android project.
|
||||||
* Returns a promise, fulfilled if the package name is acceptable; rejected
|
* 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(project_template_dir, 'res'), project_path);
|
||||||
shell.cp('-r', path.join(ROOT, 'framework', 'res', 'xml'), path.join(project_path, 'res'));
|
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).
|
// Manually create directories that would be empty within the template (since git doesn't track directories).
|
||||||
shell.mkdir(path.join(project_path, 'libs'));
|
shell.mkdir(path.join(project_path, 'libs'));
|
||||||
|
|
||||||
|
19
bin/templates/cordova/lib/build.js
vendored
19
bin/templates/cordova/lib/build.js
vendored
@ -51,6 +51,24 @@ function hasCustomRules() {
|
|||||||
return fs.existsSync(path.join(ROOT, 'custom_rules.xml'));
|
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 = {
|
module.exports.builders = {
|
||||||
ant: {
|
ant: {
|
||||||
getArgs: function(cmd) {
|
getArgs: function(cmd) {
|
||||||
@ -129,6 +147,7 @@ module.exports.builders = {
|
|||||||
var builder = this;
|
var builder = this;
|
||||||
var wrapper = path.join(ROOT, 'gradlew');
|
var wrapper = path.join(ROOT, 'gradlew');
|
||||||
var args = builder.getArgs('build');
|
var args = builder.getArgs('build');
|
||||||
|
copyGradleWrapper();
|
||||||
return Q().then(function() {
|
return Q().then(function() {
|
||||||
return spawn(wrapper, args);
|
return spawn(wrapper, args);
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user