You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2015/09/01 08:21:12 UTC

android commit: CB-9557 Fixes apk install failure when switching from debug to release build

Repository: cordova-android
Updated Branches:
  refs/heads/master 055e3bf60 -> bf57aa1df


CB-9557 Fixes apk install failure when switching from debug to release build


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/bf57aa1d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/bf57aa1d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/bf57aa1d

Branch: refs/heads/master
Commit: bf57aa1df061b3fcd429bb8d673de02bcb26f872
Parents: 055e3bf
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Wed Aug 26 16:09:27 2015 +0300
Committer: Vladimir Kotikov <v-...@microsoft.com>
Committed: Thu Aug 27 09:46:58 2015 +0300

----------------------------------------------------------------------
 bin/templates/cordova/lib/appinfo.js  | 11 +++++--
 bin/templates/cordova/lib/device.js   | 13 ++++++--
 bin/templates/cordova/lib/emulator.js | 52 +++++++++++++++++-------------
 3 files changed, 48 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/bf57aa1d/bin/templates/cordova/lib/appinfo.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/appinfo.js b/bin/templates/cordova/lib/appinfo.js
index 080c2ba..e37b89b 100644
--- a/bin/templates/cordova/lib/appinfo.js
+++ b/bin/templates/cordova/lib/appinfo.js
@@ -33,9 +33,16 @@ function readAppInfoFromManifest() {
     var activityName = /\bandroid:name\s*=\s*"(.+?)"/.exec(activityTag);
     if (!activityName) throw new Error('Could not find android:name within ' + manifestPath);
 
-    return packageName[1] + '/.' + activityName[1];
+    return (cachedAppInfo = {
+        packageName: packageName[1],
+        activityName: packageName[1] + '/.' + activityName[1]
+    });
 }
 
 exports.getActivityName = function() {
-    return (cachedAppInfo = cachedAppInfo || readAppInfoFromManifest());
+    return cachedAppInfo ? cachedAppInfo.activityName : readAppInfoFromManifest().activityName;
+};
+
+exports.getPackageName = function() {
+    return cachedAppInfo ? cachedAppInfo.packageName : readAppInfoFromManifest().packageName;
 };

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/bf57aa1d/bin/templates/cordova/lib/device.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/device.js b/bin/templates/cordova/lib/device.js
index c13fdc4..560f26d 100644
--- a/bin/templates/cordova/lib/device.js
+++ b/bin/templates/cordova/lib/device.js
@@ -96,10 +96,17 @@ module.exports.install = function(target, buildResults) {
     }).then(function(resolvedTarget) {
         var apk_path = build.findBestApkForArchitecture(buildResults, resolvedTarget.arch);
         var launchName = appinfo.getActivityName();
+        var pkgName = appinfo.getPackageName();
         console.log('Using apk: ' + apk_path);
-        console.log('Installing app on device...');
-        var cmd = 'adb -s ' + resolvedTarget.target + ' install -r "' + apk_path + '"';
-        return exec(cmd, os.tmpdir())
+        console.log('Uninstalling ' + pkgName + ' from device...');
+        // 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.
+        return exec('adb -s ' + resolvedTarget.target + ' uninstall ' + pkgName, os.tmpdir())
+        .then(function() {
+            console.log('Installing app on device...');
+            var cmd = 'adb -s ' + resolvedTarget.target + ' install -r -d "' + apk_path + '"';
+            return exec(cmd, os.tmpdir());
+        })
         .then(function(output) {
             if (output.match(/Failure/)) return Q.reject('ERROR: Failed to install apk to device: ' + output);
 

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/bf57aa1d/bin/templates/cordova/lib/emulator.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/emulator.js b/bin/templates/cordova/lib/emulator.js
index 8fbdbc1..a27d0d3 100644
--- a/bin/templates/cordova/lib/emulator.js
+++ b/bin/templates/cordova/lib/emulator.js
@@ -326,31 +326,37 @@ module.exports.install = function(givenTarget, buildResults) {
 
     // install the app
     }).then(function () {
+        var pkgName = appinfo.getPackageName();
+        console.log('Uninstalling ' + pkgName + ' from emulator...');
+        // 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.
+        return exec('adb -s ' + target.target + ' uninstall ' + pkgName, os.tmpdir())
+        .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);
-
-        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');
-            }
-        }, function (err) {
-            return Q.reject('Failed to install apk to emulator: ' + err);
-        });
+            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);
+
+            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');
+                }
+            }, function (err) {
+                return Q.reject('Failed to install apk to emulator: ' + err);
+            });
+        });
     // unlock screen
     }).then(function () {
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org