[
https://issues.apache.org/jira/browse/CB-9119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14579102#comment-14579102
]
ASF GitHub Bot commented on CB-9119:
------------------------------------
Github user nikhilkh commented on a diff in the pull request:
https://github.com/apache/cordova-android/pull/180#discussion_r32027248
--- Diff: bin/templates/cordova/lib/emulator.js ---
@@ -298,37 +306,67 @@ module.exports.resolveTarget = function(target) {
* If no started emulators are found, error out.
* Returns a promise.
*/
-module.exports.install = function(target, buildResults) {
- return Q().then(function() {
- if (target && typeof target == 'object') {
- return target;
+module.exports.install = function(givenTarget, buildResults) {
+
+ var target;
+
+ // resolve the target emulator
+ return Q().then(function () {
+ if (givenTarget && typeof givenTarget == 'object') {
+ return givenTarget;
+ } else {
+ return module.exports.resolveTarget(givenTarget);
}
- return module.exports.resolveTarget(target);
- }).then(function(resolvedTarget) {
- var apk_path = build.findBestApkForArchitecture(buildResults,
resolvedTarget.arch);
+
+ // set the resolved target
+ }).then(function (resolvedTarget) {
+ target = resolvedTarget;
+
+ // install the app
+ }).then(function () {
+
+ var apk_path = build.findBestApkForArchitecture(buildResults,
target.arch);
+ var execOptions = {
+ timeout: INSTALL_COMMAND_TIMEOUT, // in milliseconds
+ killSignal: EXEC_KILL_SIGNAL
+ };
+
console.log('Installing app on emulator...');
console.log('Using apk: ' + apk_path);
- return exec('adb -s ' + resolvedTarget.target + ' install -r -d "'
+ apk_path + '"', os.tmpdir())
- .then(function(output) {
+
+ var retriedInstall = retry.retryPromise(
+ NUM_INSTALL_RETRIES,
+ exec, 'adb -s ' + target.target + ' install -r -d "' +
apk_path + '"', os.tmpdir(), execOptions
+ );
+
+ return retriedInstall.then(function (output) {
if (output.match(/Failure/)) {
return Q.reject('Failed to install apk to emulator: ' +
output);
+ } else {
+ console.log('INSTALL SUCCESS');
}
- return Q();
- }, function(err) {
+ }, function (err) {
return Q.reject('Failed to install apk to emulator: ' + err);
- }).then(function() {
- //unlock screen
- return exec('adb -s ' + resolvedTarget.target + ' shell input
keyevent 82', os.tmpdir());
- }).then(function() {
- // launch the application
- console.log('Launching application...');
- var launchName = appinfo.getActivityName();
- var cmd = 'adb -s ' + resolvedTarget.target + ' shell am start
-W -a android.intent.action.MAIN -n ' + launchName;
- return exec(cmd, os.tmpdir());
- }).then(function(output) {
- console.log('LAUNCH SUCCESS');
- }, function(err) {
- return Q.reject('Failed to launch app on emulator: ' + err);
});
+
+ // unlock screen
+ }).then(function () {
+
+ console.log('Unlocking screen...');
+ return exec('adb -s ' + target.target + ' shell input keyevent
82', os.tmpdir());
+
+ // launch the application
--- End diff --
The comment should be added when the console log gets removed in that case.
Following the DRY principle - Don't Repeat Yourself.
> ADB install in automation sometimes hangs the emulator
> ------------------------------------------------------
>
> Key: CB-9119
> URL: https://issues.apache.org/jira/browse/CB-9119
> Project: Apache Cordova
> Issue Type: Bug
> Components: Android
> Affects Versions: Master
> Reporter: Dmitry Blotsky
> Assignee: Dmitry Blotsky
> Priority: Critical
> Labels: adb, android, hang, hard_to_verify
> Original Estimate: 72h
> Remaining Estimate: 72h
>
> Sometimes "adb install ..." hangs indefinitely when running "cordova run"
> under medic. Jenkins also sees this. Related links below.
> Android bug: http://code.google.com/p/android/issues/detail?id=10255
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]