[Flutter Tool] Only uninstall Android app when the initial install fails (#8930)

Uninstalling the app removes the data and cache directories, so this
allows application data to persist across multiple flutter run
invocations.

This also handles the edge case where the app fails to install due to an
error in installation (e.g. debug keystore changes, switching from a
release keystore to a debug keystore, etc.).
This commit is contained in:
Dwayne Slater
2017-04-04 13:16:42 -04:00
committed by Adam Barth
parent dbc447b19a
commit eb9046b175

View File

@@ -263,18 +263,28 @@ class AndroidDevice extends Device {
}
bool _installLatestApp(ApplicationPackage package) {
if (isAppInstalled(package)) {
final bool wasInstalled = isAppInstalled(package);
if (wasInstalled) {
if (isLatestBuildInstalled(package)) {
printStatus('Latest build already installed.');
printTrace('Latest build already installed.');
return true;
}
printStatus('Uninstalling old version...');
if (!uninstallApp(package))
printError('Warning: uninstalling old version failed');
}
printTrace('Installing APK.');
if (!installApp(package)) {
printTrace('Error: Failed to install APK.');
printTrace('Warning: Failed to install APK.');
if (wasInstalled) {
printStatus('Uninstalling old version...');
if (!uninstallApp(package)) {
printError('Error: Uninstalling old version failed.');
return false;
}
if (!installApp(package)) {
printError('Error: Failed to install APK again.');
return false;
}
return true;
}
return false;
}
return true;