From e621edfba755d31915da29a6113b0be2db56735f Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Fri, 21 Apr 2017 16:27:26 -0700 Subject: [PATCH] Fixing the Android Studio detection and making it automatically pick the right builder, good for upgrading Cordova --- bin/lib/create.js | 10 ++++++---- bin/templates/cordova/Api.js | 2 ++ bin/templates/cordova/lib/AndroidStudio.js | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bin/lib/create.js b/bin/lib/create.js index e7c39bd6..bb48791c 100755 --- a/bin/lib/create.js +++ b/bin/lib/create.js @@ -45,7 +45,9 @@ function getFrameworkDir(projectPath, shared) { function copyJsAndLibrary(projectPath, shared, projectName) { var nestedCordovaLibPath = getFrameworkDir(projectPath, false); var srcCordovaJsPath = path.join(ROOT, 'bin', 'templates', 'project', 'assets', 'www', 'cordova.js'); - shell.cp('-f', srcCordovaJsPath, path.join(projectPath, 'app', 'src', 'main', 'assets', 'www', 'cordova.js')); + var app_path = path.join(projectPath, 'app', 'src', 'main'); + + shell.cp('-f', srcCordovaJsPath, path.join(app_path, 'assets', 'www', 'cordova.js')); // Copy the cordova.js file to platforms//platform_www/ // The www dir is nuked on each prepare so we keep cordova.js in platform_www @@ -56,9 +58,9 @@ function copyJsAndLibrary(projectPath, shared, projectName) { // We need these files to build cordova.js if using browserify method. shell.cp('-rf', path.join(ROOT, 'cordova-js-src'), path.join(projectPath, 'platform_www')); - // Don't fail if there are no old jars. + // Don't fail if there are no old jars, because there hasn't been cordova JARs for years! setShellFatal(false, function() { - shell.ls(path.join(projectPath, 'libs', 'cordova-*.jar')).forEach(function(oldJar) { + shell.ls(path.join(app_path, 'libs', 'cordova-*.jar')).forEach(function(oldJar) { console.log('Deleting ' + oldJar); shell.rm('-f', oldJar); }); @@ -270,7 +272,7 @@ exports.create = function(project_path, config, options, events) { shell.cp(path.join(project_template_dir, 'gitignore'), path.join(project_path, '.gitignore')); // 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(app_path, 'libs')); // copy cordova.js, cordova.jar copyJsAndLibrary(project_path, options.link, safe_activity_name); diff --git a/bin/templates/cordova/Api.js b/bin/templates/cordova/Api.js index 8e4711cb..4422d074 100644 --- a/bin/templates/cordova/Api.js +++ b/bin/templates/cordova/Api.js @@ -343,6 +343,8 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) { */ Api.prototype.build = function (buildOptions) { var self = this; + if(this.android_studio) + buildOptions.studio = true; return require('./lib/check_reqs').run() .then(function () { return require('./lib/build').run.call(self, buildOptions); diff --git a/bin/templates/cordova/lib/AndroidStudio.js b/bin/templates/cordova/lib/AndroidStudio.js index 335b334b..2e7db00a 100644 --- a/bin/templates/cordova/lib/AndroidStudio.js +++ b/bin/templates/cordova/lib/AndroidStudio.js @@ -11,7 +11,7 @@ var fs = require('fs'); var CordovaError = require('cordova-common').CordovaError; module.exports.isAndroidStudioProject = function isAndroidStudioProject(root) { - var eclipseFiles = ['AndroidManifest.xml', 'libs', 'res', 'project.properties', 'platform_www']; + var eclipseFiles = ['AndroidManifest.xml', 'libs', 'res']; var androidStudioFiles = ['app', 'gradle', 'app/src/main/res']; // assume it is an AS project and not an Eclipse project