mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-21 08:12:56 +08:00
parent
e9e27ca47c
commit
9738079c42
@ -246,7 +246,7 @@ exports.create = function(project_path, config, options, events) {
|
||||
events.emit('log', '\tActivity: ' + safe_activity_name);
|
||||
events.emit('log', '\tAndroid target: ' + target_api);
|
||||
|
||||
events.emit('verbose', 'Copying template files...');
|
||||
events.emit('verbose', 'Copying android template project to ' + project_path);
|
||||
|
||||
setShellFatal(true, function() {
|
||||
var project_template_dir = options.customTemplate || path.join(ROOT, 'bin', 'templates', 'project');
|
||||
|
8
bin/templates/cordova/lib/Adb.js
vendored
8
bin/templates/cordova/lib/Adb.js
vendored
@ -56,7 +56,7 @@ Adb.devices = function (opts) {
|
||||
};
|
||||
|
||||
Adb.install = function (target, packagePath, opts) {
|
||||
events.emit('verbose', 'Installing apk ' + packagePath + ' on ' + target + '...');
|
||||
events.emit('verbose', 'Installing apk ' + packagePath + ' on target ' + target + '...');
|
||||
var args = ['-s', target, 'install'];
|
||||
if (opts && opts.replace) args.push('-r');
|
||||
return spawn('adb', args.concat(packagePath), {cwd: os.tmpdir()})
|
||||
@ -78,12 +78,12 @@ Adb.install = function (target, packagePath, opts) {
|
||||
};
|
||||
|
||||
Adb.uninstall = function (target, packageId) {
|
||||
events.emit('verbose', 'Uninstalling ' + packageId + ' from ' + target + '...');
|
||||
events.emit('verbose', 'Uninstalling package ' + packageId + ' from target ' + target + '...');
|
||||
return spawn('adb', ['-s', target, 'uninstall', packageId], {cwd: os.tmpdir()});
|
||||
};
|
||||
|
||||
Adb.shell = function (target, shellCommand) {
|
||||
events.emit('verbose', 'Running command "' + shellCommand + '" on ' + target + '...');
|
||||
events.emit('verbose', 'Running adb shell command "' + shellCommand + '" on target ' + target + '...');
|
||||
var args = ['-s', target, 'shell'];
|
||||
shellCommand = shellCommand.split(/\s+/);
|
||||
return spawn('adb', args.concat(shellCommand), {cwd: os.tmpdir()})
|
||||
@ -94,7 +94,7 @@ Adb.shell = function (target, shellCommand) {
|
||||
};
|
||||
|
||||
Adb.start = function (target, activityName) {
|
||||
events.emit('verbose', 'Starting application "' + activityName + '" on ' + target + '...');
|
||||
events.emit('verbose', 'Starting application "' + activityName + '" on target ' + target + '...');
|
||||
return Adb.shell(target, 'am start -W -a android.intent.action.MAIN -n' + activityName)
|
||||
.catch(function (output) {
|
||||
return Q.reject(new CordovaError('Failed to start application "' +
|
||||
|
2
bin/templates/cordova/lib/AndroidManifest.js
vendored
2
bin/templates/cordova/lib/AndroidManifest.js
vendored
@ -28,7 +28,7 @@ function AndroidManifest(path) {
|
||||
this.path = path;
|
||||
this.doc = xml.parseElementtreeSync(path);
|
||||
if (this.doc.getroot().tag !== 'manifest') {
|
||||
throw new Error(path + ' has incorrect root node name (expected "manifest")');
|
||||
throw new Error('AndroidManifest at ' + path + ' has incorrect root node name (expected "manifest")');
|
||||
}
|
||||
}
|
||||
|
||||
|
6
bin/templates/cordova/lib/build.js
vendored
6
bin/templates/cordova/lib/build.js
vendored
@ -188,18 +188,18 @@ module.exports.detectArchitecture = function(target) {
|
||||
// adb kill-server doesn't seem to do the trick.
|
||||
// Could probably find a x-platform version of killall, but I'm not actually
|
||||
// sure that this scenario even happens on non-OSX machines.
|
||||
events.emit('verbose', 'adb timed out while detecting device/emulator architecture. Killing adb and trying again.');
|
||||
return spawn('killall', ['adb'])
|
||||
.then(function() {
|
||||
events.emit('verbose', 'adb seems hung. retrying.');
|
||||
return helper()
|
||||
.then(null, function() {
|
||||
// The double kill is sadly often necessary, at least on mac.
|
||||
events.emit('warn', 'Now device not found... restarting adb again.');
|
||||
events.emit('warn', 'adb timed out a second time while detecting device/emulator architecture. Killing adb and trying again.');
|
||||
return spawn('killall', ['adb'])
|
||||
.then(function() {
|
||||
return helper()
|
||||
.then(null, function() {
|
||||
return Q.reject(new CordovaError('USB is flakey. Try unplugging & replugging the device.'));
|
||||
return Q.reject(new CordovaError('adb timed out a third time while detecting device/emulator architecture. Try unplugging & replugging the device.'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -79,7 +79,7 @@ AntBuilder.prototype.prepEnv = function(opts) {
|
||||
writeBuildXml(path.join(self.root, subProjects[i]));
|
||||
}
|
||||
if (propertiesObj.systemLibs.length > 0) {
|
||||
throw new CordovaError('Project contains at least one plugin that requires a system library. This is not supported with ANT. Please build using gradle.');
|
||||
throw new CordovaError('Project contains at least one plugin that requires a system library. This is not supported with ANT. Use gradle instead.');
|
||||
}
|
||||
|
||||
var propertiesFile = opts.buildType + SIGNING_PROPERTIES;
|
||||
|
14
bin/templates/cordova/lib/emulator.js
vendored
14
bin/templates/cordova/lib/emulator.js
vendored
@ -187,14 +187,14 @@ module.exports.start = function(emulator_ID, boot_timeout) {
|
||||
.unref();
|
||||
|
||||
// wait for emulator to start
|
||||
events.emit('log', 'Waiting for emulator...');
|
||||
events.emit('log', 'Waiting for emulator to start...');
|
||||
return self.wait_for_emulator(uuid);
|
||||
}).then(function(emulatorId) {
|
||||
if (!emulatorId)
|
||||
return Q.reject(new CordovaError('Failed to start emulator'));
|
||||
|
||||
//wait for emulator to boot up
|
||||
process.stdout.write('Booting up emulator (this may take a while)...');
|
||||
process.stdout.write('Waiting for emulator to boot (this may take a while)...');
|
||||
return self.wait_for_boot(emulatorId, boot_timeout)
|
||||
.then(function(success) {
|
||||
if (success) {
|
||||
@ -272,7 +272,7 @@ module.exports.wait_for_boot = function(emulator_id, time_remaining) {
|
||||
* Returns a promise.
|
||||
*/
|
||||
module.exports.create_image = function(name, target) {
|
||||
console.log('Creating avd named ' + name);
|
||||
console.log('Creating new avd named ' + name);
|
||||
if (target) {
|
||||
return spawn('android', ['create', 'avd', '--name', name, '--target', target])
|
||||
.then(null, function(error) {
|
||||
@ -286,7 +286,7 @@ module.exports.create_image = function(name, target) {
|
||||
.then(function() {
|
||||
// TODO: This seems like another error case, even though it always happens.
|
||||
console.error('ERROR : Unable to create an avd emulator, no targets found.');
|
||||
console.error('Please insure you have targets available by running the "android" command');
|
||||
console.error('Ensure you have targets available by running the "android" command');
|
||||
return Q.reject();
|
||||
}, function(error) {
|
||||
console.error('ERROR : Failed to create emulator image : ');
|
||||
@ -299,7 +299,7 @@ module.exports.resolveTarget = function(target) {
|
||||
return this.list_started()
|
||||
.then(function(emulator_list) {
|
||||
if (emulator_list.length < 1) {
|
||||
return Q.reject('No started emulators found, please start an emultor before deploying your project.');
|
||||
return Q.reject('No running Android emulators found, please start an emulator before deploying your project.');
|
||||
}
|
||||
|
||||
// default emulator
|
||||
@ -392,8 +392,8 @@ module.exports.install = function(givenTarget, buildResults) {
|
||||
if (!/INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES/.test(error.toString()))
|
||||
throw error;
|
||||
|
||||
events.emit('warn', 'Uninstalling app from device and reinstalling it again because the ' +
|
||||
'installed app already signed with different key');
|
||||
events.emit('warn', 'Uninstalling app from device and reinstalling it because the ' +
|
||||
'currently installed app was signed with different key');
|
||||
|
||||
// This promise is always resolved, even if 'adb uninstall' fails to uninstall app
|
||||
// or the app doesn't installed at all, so no error catching needed.
|
||||
|
22
bin/templates/cordova/lib/pluginHandlers.js
vendored
22
bin/templates/cordova/lib/pluginHandlers.js
vendored
@ -28,8 +28,8 @@ var CordovaError = require('cordova-common').CordovaError;
|
||||
var handlers = {
|
||||
'source-file':{
|
||||
install:function(obj, plugin, project, options) {
|
||||
if (!obj.src) throw new CordovaError('<source-file> element is missing "src" attribute for plugin: ' + plugin.id);
|
||||
if (!obj.targetDir) throw new CordovaError('<source-file> element is missing "target-dir" attribute for plugin: ' + plugin.id);
|
||||
if (!obj.src) throw new CordovaError(generateAttributeError('src', 'source-file', plugin.id));
|
||||
if (!obj.targetDir) throw new CordovaError(generateAttributeError('target-dir', 'source-file', plugin.id));
|
||||
var dest = path.join(obj.targetDir, path.basename(obj.src));
|
||||
if (options && options.force) {
|
||||
copyFile(plugin.dir, obj.src, project.projectDir, dest, !!(options && options.link));
|
||||
@ -63,7 +63,7 @@ var handlers = {
|
||||
'framework': {
|
||||
install:function(obj, plugin, project, options) {
|
||||
var src = obj.src;
|
||||
if (!src) throw new CordovaError('src not specified in <framework> for plugin: ' + plugin.id);
|
||||
if (!src) throw new CordovaError(generateAttributeError('src', 'framework', plugin.id));
|
||||
|
||||
events.emit('verbose', 'Installing Android library: ' + src);
|
||||
var parentDir = obj.parent ? path.resolve(project.projectDir, obj.parent) : project.projectDir;
|
||||
@ -88,7 +88,7 @@ var handlers = {
|
||||
},
|
||||
uninstall:function(obj, plugin, project, options) {
|
||||
var src = obj.src;
|
||||
if (!src) throw new CordovaError('src not specified in <framework> for plugin: ' + plugin.id);
|
||||
if (!src) throw new CordovaError(generateAttributeError('src', 'framework', plugin.id));
|
||||
|
||||
events.emit('verbose', 'Uninstalling Android library: ' + src);
|
||||
var parentDir = obj.parent ? path.resolve(project.projectDir, obj.parent) : project.projectDir;
|
||||
@ -120,10 +120,10 @@ var handlers = {
|
||||
asset:{
|
||||
install:function(obj, plugin, project, options) {
|
||||
if (!obj.src) {
|
||||
throw new CordovaError('<asset> tag without required "src" attribute. plugin=' + plugin.dir);
|
||||
throw new CordovaError(generateAttributeError('src', 'asset', plugin.id));
|
||||
}
|
||||
if (!obj.target) {
|
||||
throw new CordovaError('<asset> tag without required "target" attribute');
|
||||
throw new CordovaError(generateAttributeError('target', 'asset', plugin.id));
|
||||
}
|
||||
|
||||
copyFile(plugin.dir, obj.src, project.www, obj.target);
|
||||
@ -135,7 +135,7 @@ var handlers = {
|
||||
uninstall:function(obj, plugin, project, options) {
|
||||
var target = obj.target || obj.src;
|
||||
|
||||
if (!target) throw new CordovaError('<asset> tag without required "target" attribute');
|
||||
if (!target) throw new CordovaError(generateAttributeError('target', 'asset', plugin.id));
|
||||
|
||||
removeFileF(path.resolve(project.www, target));
|
||||
removeFileF(path.resolve(project.www, 'plugins', plugin.id));
|
||||
@ -205,13 +205,13 @@ function copyFile (plugin_dir, src, project_dir, dest, link) {
|
||||
var real_path = fs.realpathSync(src);
|
||||
var real_plugin_path = fs.realpathSync(plugin_dir);
|
||||
if (real_path.indexOf(real_plugin_path) !== 0)
|
||||
throw new CordovaError('"' + src + '" not located within plugin!');
|
||||
throw new CordovaError('File "' + src + '" is located outside the plugin directory "' + plugin_dir + '"');
|
||||
|
||||
dest = path.resolve(project_dir, dest);
|
||||
|
||||
// check that dest path is located in project directory
|
||||
if (dest.indexOf(project_dir) !== 0)
|
||||
throw new CordovaError('"' + dest + '" not located within project!');
|
||||
throw new CordovaError('Destination "' + dest + '" for source file "' + src + '" is located outside the project');
|
||||
|
||||
shell.mkdir('-p', path.dirname(dest));
|
||||
|
||||
@ -270,3 +270,7 @@ function removeFileAndParents (baseDir, destFile, stopper) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function generateAttributeError(attribute, element, id) {
|
||||
return 'Required attribute "' + attribute + '" not specified in <' + element + '> element from plugin: ' + id;
|
||||
}
|
||||
|
21
bin/templates/cordova/lib/prepare.js
vendored
21
bin/templates/cordova/lib/prepare.js
vendored
@ -50,7 +50,7 @@ module.exports.prepare = function (cordovaProject) {
|
||||
handleSplashes(cordovaProject.projectConfig, self.root);
|
||||
})
|
||||
.then(function () {
|
||||
events.emit('verbose', 'updated project successfully');
|
||||
events.emit('verbose', 'Prepared android project successfully');
|
||||
});
|
||||
};
|
||||
|
||||
@ -69,7 +69,7 @@ module.exports.prepare = function (cordovaProject) {
|
||||
* configuration is already dumped to appropriate config.xml file.
|
||||
*/
|
||||
function updateConfigFilesFrom(sourceConfig, configMunger, locations) {
|
||||
events.emit('verbose', 'Generating config.xml from defaults for platform "android"');
|
||||
events.emit('verbose', 'Generating platform-specific config.xml from defaults for android at ' + locations.configXml);
|
||||
|
||||
// First cleanup current config and merge project's one into own
|
||||
// Overwrite platform config.xml with defaults.xml.
|
||||
@ -79,6 +79,7 @@ function updateConfigFilesFrom(sourceConfig, configMunger, locations) {
|
||||
// in project (including project's config)
|
||||
configMunger.reapply_global_munge().save_all();
|
||||
|
||||
events.emit('verbose', 'Merging project\'s config.xml into platform-specific android config.xml');
|
||||
// Merge changes from app's config.xml into platform's one
|
||||
var config = new ConfigParser(locations.configXml);
|
||||
xmlHelpers.mergeXml(sourceConfig.doc.getroot(),
|
||||
@ -108,7 +109,7 @@ function updateWwwFrom(cordovaProject, destinations) {
|
||||
// If project contains 'merges' for our platform, use them as another overrides
|
||||
var merges_path = path.join(cordovaProject.root, 'merges', 'android');
|
||||
if (fs.existsSync(merges_path)) {
|
||||
events.emit('verbose', 'Found "merges" for android platform. Copying over existing "www" files.');
|
||||
events.emit('verbose', 'Found "merges/android" folder. Copying its contents into the android project.');
|
||||
var overrides = path.join(merges_path, '*');
|
||||
shell.cp('-rf', overrides, destinations.www);
|
||||
}
|
||||
@ -127,7 +128,7 @@ function updateProjectAccordingTo(platformConfig, locations) {
|
||||
var strings = xmlHelpers.parseElementtreeSync(locations.strings);
|
||||
strings.find('string[@name="app_name"]').text = name;
|
||||
fs.writeFileSync(locations.strings, strings.write({indent: 4}), 'utf-8');
|
||||
events.emit('verbose', 'Wrote out Android application name to "' + name + '"');
|
||||
events.emit('verbose', 'Wrote out android application name "' + name + '" to ' + locations.strings);
|
||||
|
||||
// Java packages cannot support dashes
|
||||
var pkg = (platformConfig.android_packageName() || platformConfig.packageName()).replace(/-/g, '_');
|
||||
@ -153,15 +154,15 @@ function updateProjectAccordingTo(platformConfig, locations) {
|
||||
});
|
||||
|
||||
if (java_files.length === 0) {
|
||||
throw new CordovaError('No Java files found which extend CordovaActivity.');
|
||||
throw new CordovaError('No Java files found that extend CordovaActivity.');
|
||||
} else if(java_files.length > 1) {
|
||||
events.emit('log', 'Multiple candidate Java files (.java files which extend CordovaActivity) found. Guessing at the first one, ' + java_files[0]);
|
||||
events.emit('log', 'Multiple candidate Java files that extend CordovaActivity found. Guessing at the first one, ' + java_files[0]);
|
||||
}
|
||||
|
||||
var destFile = path.join(locations.root, 'src', pkg.replace(/\./g, '/'), path.basename(java_files[0]));
|
||||
shell.mkdir('-p', path.dirname(destFile));
|
||||
shell.sed(/package [\w\.]*;/, 'package ' + pkg + ';', java_files[0]).to(destFile);
|
||||
events.emit('verbose', 'Wrote out Android package name to "' + pkg + '"');
|
||||
events.emit('verbose', 'Wrote out Android package name "' + pkg + '" to ' + destFile);
|
||||
|
||||
if (orig_pkg !== pkg) {
|
||||
// If package was name changed we need to remove old java with main activity
|
||||
@ -195,6 +196,8 @@ function default_versionCode(version) {
|
||||
if (+nums[2]) {
|
||||
versionCode += +nums[2];
|
||||
}
|
||||
|
||||
events.emit('verbose', 'android-versionCode not found in config.xml. Generating a code based on version in config.xml (' + version + '): ' + versionCode);
|
||||
return versionCode;
|
||||
}
|
||||
|
||||
@ -209,7 +212,7 @@ function copyImage(src, resourcesDir, density, name) {
|
||||
}
|
||||
|
||||
var destFilePath = path.join(destFolder, isNinePatch ? ninePatchName : name);
|
||||
events.emit('verbose', 'copying image from ' + src + ' to ' + destFilePath);
|
||||
events.emit('verbose', 'Copying image from ' + src + ' to ' + destFilePath);
|
||||
shell.cp('-f', src, destFilePath);
|
||||
}
|
||||
|
||||
@ -289,7 +292,7 @@ function handleIcons(projectConfig, platformRoot) {
|
||||
}
|
||||
if (!size && !icon.density) {
|
||||
if (default_icon) {
|
||||
events.emit('verbose', 'more than one default icon: ' + JSON.stringify(icon));
|
||||
events.emit('verbose', 'Found extra default icon: ' + icon.src + ' (ignoring in favor of ' + default_icon.src + ')');
|
||||
} else {
|
||||
default_icon = icon;
|
||||
}
|
||||
|
2
bin/templates/cordova/lib/run.js
vendored
2
bin/templates/cordova/lib/run.js
vendored
@ -66,7 +66,7 @@ function getInstallTarget(runOptions) {
|
||||
events.emit('warn', 'No target specified, deploying to device \'' + device_list[0] + '\'.');
|
||||
install_target = device_list[0];
|
||||
} else {
|
||||
events.emit('warn', 'No target specified, deploying to emulator');
|
||||
events.emit('warn', 'No target specified and no devices found, deploying to emulator');
|
||||
install_target = '--emulator';
|
||||
}
|
||||
});
|
||||
|
@ -61,7 +61,7 @@ String doFindLatestInstalledBuildTools(String minBuildToolsVersion) {
|
||||
highestBuildToolsVersion
|
||||
} else {
|
||||
throw new RuntimeException(
|
||||
"No installed build tools found. Please install the Android build tools version " +
|
||||
"No installed build tools found. Install the Android build tools version " +
|
||||
minBuildToolsVersion + " or higher.")
|
||||
}
|
||||
}
|
||||
|
@ -47,8 +47,9 @@ describe('common platform handler', function() {
|
||||
it('should throw if src not in plugin directory', function(){
|
||||
shell.mkdir('-p', project_dir);
|
||||
fs.writeFileSync(non_plugin_file, 'contents', 'utf-8');
|
||||
expect(function(){copyFile(test_dir, '../non_plugin_file', project_dir, dest);}).
|
||||
toThrow(new Error('"' + non_plugin_file + '" not located within plugin!'));
|
||||
var outside_file = '../non_plugin_file';
|
||||
expect(function(){copyFile(test_dir, outside_file, project_dir, dest);}).
|
||||
toThrow(new Error('File "' + path.resolve(test_dir, outside_file) + '" is located outside the plugin directory "' + test_dir + '"'));
|
||||
shell.rm('-rf', test_dir);
|
||||
});
|
||||
|
||||
@ -75,7 +76,7 @@ describe('common platform handler', function() {
|
||||
}
|
||||
|
||||
expect(function(){copyFile(test_dir, symlink_file, project_dir, dest);}).
|
||||
toThrow(new Error('"' + symlink_file + '" not located within plugin!'));
|
||||
toThrow(new Error('File "' + path.resolve(test_dir, symlink_file) + '" is located outside the plugin directory "' + test_dir + '"'));
|
||||
shell.rm('-rf', project_dir);
|
||||
});
|
||||
|
||||
@ -83,7 +84,7 @@ describe('common platform handler', function() {
|
||||
shell.mkdir('-p', java_dir);
|
||||
fs.writeFileSync(java_file, 'contents', 'utf-8');
|
||||
expect(function(){copyFile(test_dir, java_file, project_dir, non_plugin_file);}).
|
||||
toThrow(new Error('"' + non_plugin_file + '" not located within project!'));
|
||||
toThrow(new Error('Destination "' + path.resolve(project_dir, non_plugin_file) + '" for source file "' + path.resolve(test_dir, java_file) + '" is located outside the project'));
|
||||
shell.rm('-rf', project_dir);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user