mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-20 23:56:20 +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);
|
||||
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;
|
||||
};
|
||||
|
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) {
|
||||
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);
|
||||
|
||||
|
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
|
||||
}).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
|
||||
};
|
||||
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);
|
||||
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
|
||||
);
|
||||
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);
|
||||
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 () {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user