mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
CB-9557 Fixes apk install failure when switching from debug to release build
This commit is contained in:
parent
055e3bf609
commit
bf57aa1df0
11
bin/templates/cordova/lib/appinfo.js
vendored
11
bin/templates/cordova/lib/appinfo.js
vendored
@ -33,9 +33,16 @@ function readAppInfoFromManifest() {
|
|||||||
var activityName = /\bandroid:name\s*=\s*"(.+?)"/.exec(activityTag);
|
var activityName = /\bandroid:name\s*=\s*"(.+?)"/.exec(activityTag);
|
||||||
if (!activityName) throw new Error('Could not find android:name within ' + manifestPath);
|
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() {
|
exports.getActivityName = function() {
|
||||||
return (cachedAppInfo = cachedAppInfo || readAppInfoFromManifest());
|
return cachedAppInfo ? cachedAppInfo.activityName : readAppInfoFromManifest().activityName;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getPackageName = function() {
|
||||||
|
return cachedAppInfo ? cachedAppInfo.packageName : readAppInfoFromManifest().packageName;
|
||||||
};
|
};
|
||||||
|
13
bin/templates/cordova/lib/device.js
vendored
13
bin/templates/cordova/lib/device.js
vendored
@ -96,10 +96,17 @@ module.exports.install = function(target, buildResults) {
|
|||||||
}).then(function(resolvedTarget) {
|
}).then(function(resolvedTarget) {
|
||||||
var apk_path = build.findBestApkForArchitecture(buildResults, resolvedTarget.arch);
|
var apk_path = build.findBestApkForArchitecture(buildResults, resolvedTarget.arch);
|
||||||
var launchName = appinfo.getActivityName();
|
var launchName = appinfo.getActivityName();
|
||||||
|
var pkgName = appinfo.getPackageName();
|
||||||
console.log('Using apk: ' + apk_path);
|
console.log('Using apk: ' + apk_path);
|
||||||
console.log('Installing app on device...');
|
console.log('Uninstalling ' + pkgName + ' from device...');
|
||||||
var cmd = 'adb -s ' + resolvedTarget.target + ' install -r "' + apk_path + '"';
|
// This promise is always resolved, even if 'adb uninstall' fails to uninstall app
|
||||||
return exec(cmd, os.tmpdir())
|
// 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) {
|
.then(function(output) {
|
||||||
if (output.match(/Failure/)) return Q.reject('ERROR: Failed to install apk to device: ' + output);
|
if (output.match(/Failure/)) return Q.reject('ERROR: Failed to install apk to device: ' + output);
|
||||||
|
|
||||||
|
46
bin/templates/cordova/lib/emulator.js
vendored
46
bin/templates/cordova/lib/emulator.js
vendored
@ -326,31 +326,37 @@ module.exports.install = function(givenTarget, buildResults) {
|
|||||||
|
|
||||||
// install the app
|
// install the app
|
||||||
}).then(function () {
|
}).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 apk_path = build.findBestApkForArchitecture(buildResults, target.arch);
|
||||||
var execOptions = {
|
var execOptions = {
|
||||||
timeout: INSTALL_COMMAND_TIMEOUT, // in milliseconds
|
timeout: INSTALL_COMMAND_TIMEOUT, // in milliseconds
|
||||||
killSignal: EXEC_KILL_SIGNAL
|
killSignal: EXEC_KILL_SIGNAL
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('Installing app on emulator...');
|
console.log('Installing app on emulator...');
|
||||||
console.log('Using apk: ' + apk_path);
|
console.log('Using apk: ' + apk_path);
|
||||||
|
|
||||||
var retriedInstall = retry.retryPromise(
|
var retriedInstall = retry.retryPromise(
|
||||||
NUM_INSTALL_RETRIES,
|
NUM_INSTALL_RETRIES,
|
||||||
exec, 'adb -s ' + target.target + ' install -r -d "' + apk_path + '"', os.tmpdir(), execOptions
|
exec, 'adb -s ' + target.target + ' install -r -d "' + apk_path + '"', os.tmpdir(), execOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
return retriedInstall.then(function (output) {
|
return retriedInstall.then(function (output) {
|
||||||
if (output.match(/Failure/)) {
|
if (output.match(/Failure/)) {
|
||||||
return Q.reject('Failed to install apk to emulator: ' + output);
|
return Q.reject('Failed to install apk to emulator: ' + output);
|
||||||
} else {
|
} else {
|
||||||
console.log('INSTALL SUCCESS');
|
console.log('INSTALL SUCCESS');
|
||||||
}
|
}
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
return Q.reject('Failed to install apk to emulator: ' + err);
|
return Q.reject('Failed to install apk to emulator: ' + err);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// unlock screen
|
// unlock screen
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user