Don't reinstall the app if the latest build is already installed. (#8328)
Only implemented for Android devices for now. Compare the installed SHA1 to the latest build. If they match, there's no reason to reinstall the build. Fixes #8295
This commit is contained in:
parent
3676ffe477
commit
a745fd58be
@ -196,6 +196,10 @@ class AndroidDevice extends Device {
|
||||
return '/data/local/tmp/sky.${app.id}.sha1';
|
||||
}
|
||||
|
||||
String _getDeviceApkSha1(ApplicationPackage app) {
|
||||
return runSync(adbCommandForDevice(<String>['shell', 'cat', _getDeviceSha1Path(app)]));
|
||||
}
|
||||
|
||||
String _getSourceSha1(ApplicationPackage app) {
|
||||
AndroidApk apk = app;
|
||||
File shaFile = fs.file('${apk.apkPath}.sha1');
|
||||
@ -212,6 +216,12 @@ class AndroidDevice extends Device {
|
||||
return LineSplitter.split(listOut).contains("package:${app.id}");
|
||||
}
|
||||
|
||||
@override
|
||||
bool isLatestBuildInstalled(ApplicationPackage app) {
|
||||
String installedSha1 = _getDeviceApkSha1(app);
|
||||
return installedSha1.isNotEmpty && installedSha1 == _getSourceSha1(app);
|
||||
}
|
||||
|
||||
@override
|
||||
bool installApp(ApplicationPackage app) {
|
||||
AndroidApk apk = app;
|
||||
@ -286,6 +296,9 @@ class AndroidDevice extends Device {
|
||||
);
|
||||
}
|
||||
|
||||
if (isLatestBuildInstalled(package)) {
|
||||
printStatus('Latest build already installed.');
|
||||
} else {
|
||||
if (isAppInstalled(package)) {
|
||||
printStatus('Uninstalling old version...');
|
||||
if (!uninstallApp(package))
|
||||
@ -297,6 +310,7 @@ class AndroidDevice extends Device {
|
||||
printTrace('Error: Failed to install APK.');
|
||||
return new LaunchResult.failed();
|
||||
}
|
||||
}
|
||||
|
||||
final bool traceStartup = platformArgs['trace-startup'] ?? false;
|
||||
final AndroidApk apk = package;
|
||||
|
@ -175,5 +175,10 @@ Future<Null> buildGradleProjectV2(String gradle, String buildModeName) async {
|
||||
File apkFile = fs.file('$gradleAppOutDir/$apkFilename');
|
||||
// Copy the APK to app.apk, so `flutter run`, `flutter install`, etc. can find it.
|
||||
apkFile.copySync('$gradleAppOutDir/app.apk');
|
||||
|
||||
printTrace('calculateSha: $gradleAppOutDir/app.apk');
|
||||
File apkShaFile = fs.file('$gradleAppOutDir/app.apk.sha1');
|
||||
apkShaFile.writeAsStringSync(calculateSha(apkFile));
|
||||
|
||||
printStatus('Built $apkFilename (${getSizeAsMB(apkFile.lengthSync())}).');
|
||||
}
|
||||
|
@ -151,6 +151,9 @@ abstract class Device {
|
||||
/// Check if a version of the given app is already installed
|
||||
bool isAppInstalled(ApplicationPackage app);
|
||||
|
||||
/// Check if the latest build of the [app] is already installed.
|
||||
bool isLatestBuildInstalled(ApplicationPackage app);
|
||||
|
||||
/// Install an app package on the current device
|
||||
bool installApp(ApplicationPackage app);
|
||||
|
||||
|
@ -152,6 +152,9 @@ class IOSDevice extends Device {
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
bool isLatestBuildInstalled(ApplicationPackage app) => false;
|
||||
|
||||
@override
|
||||
bool installApp(ApplicationPackage app) {
|
||||
IOSApp iosApp = app;
|
||||
|
@ -340,6 +340,9 @@ class IOSSimulator extends Device {
|
||||
return SimControl.instance.isInstalled(app.id);
|
||||
}
|
||||
|
||||
@override
|
||||
bool isLatestBuildInstalled(ApplicationPackage app) => false;
|
||||
|
||||
@override
|
||||
bool installApp(ApplicationPackage app) {
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user