improve progress display when running apps; speed up startup (#9475)

* improve progress display when running apps; speed up startup

* review comments
This commit is contained in:
Devon Carew
2017-04-20 07:13:35 -07:00
committed by GitHub
parent 35803c2297
commit f29dd4f921
10 changed files with 45 additions and 36 deletions

View File

@@ -222,7 +222,7 @@ class AndroidDevice extends Device {
}
@override
bool installApp(ApplicationPackage app) {
Future<bool> installApp(ApplicationPackage app) async {
final AndroidApk apk = app;
if (!fs.isFileSync(apk.apkPath)) {
printError('"${apk.apkPath}" does not exist.');
@@ -233,16 +233,18 @@ class AndroidDevice extends Device {
return false;
final Status status = logger.startProgress('Installing ${apk.apkPath}...', expectSlowOperation: true);
final String installOut = runCheckedSync(adbCommandForDevice(<String>['install', '-r', apk.apkPath]));
final RunResult installResult = await runCheckedAsync(adbCommandForDevice(<String>['install', '-r', apk.apkPath]));
status.stop();
final RegExp failureExp = new RegExp(r'^Failure.*$', multiLine: true);
final String failure = failureExp.stringMatch(installOut);
final String failure = failureExp.stringMatch(installResult.stdout);
if (failure != null) {
printError('Package install error: $failure');
return false;
}
runCheckedSync(adbCommandForDevice(<String>['shell', 'echo', '-n', _getSourceSha1(app), '>', _getDeviceSha1Path(app)]));
await runCheckedAsync(adbCommandForDevice(<String>[
'shell', 'echo', '-n', _getSourceSha1(app), '>', _getDeviceSha1Path(app)
]));
return true;
}
@@ -262,7 +264,7 @@ class AndroidDevice extends Device {
return true;
}
bool _installLatestApp(ApplicationPackage package) {
Future<bool> _installLatestApp(ApplicationPackage package) async {
final bool wasInstalled = isAppInstalled(package);
if (wasInstalled) {
if (isLatestBuildInstalled(package)) {
@@ -271,7 +273,7 @@ class AndroidDevice extends Device {
}
}
printTrace('Installing APK.');
if (!installApp(package)) {
if (!await installApp(package)) {
printTrace('Warning: Failed to install APK.');
if (wasInstalled) {
printStatus('Uninstalling old version...');
@@ -279,7 +281,7 @@ class AndroidDevice extends Device {
printError('Error: Uninstalling old version failed.');
return false;
}
if (!installApp(package)) {
if (!await installApp(package)) {
printError('Error: Failed to install APK again.');
return false;
}
@@ -325,7 +327,7 @@ class AndroidDevice extends Device {
printTrace("Stopping app '${package.name}' on $name.");
await stopApp(package);
if (!_installLatestApp(package))
if (!await _installLatestApp(package))
return new LaunchResult.failed();
final bool traceStartup = platformArgs['trace-startup'] ?? false;

View File

@@ -23,6 +23,8 @@ const String gradleManifestPath = 'android/app/src/main/AndroidManifest.xml';
const String gradleAppOutV1 = 'android/app/build/outputs/apk/app-debug.apk';
const String gradleAppOutDirV1 = 'android/app/build/outputs/apk';
String _cachedGradleAppOutDirV2;
enum FlutterPluginVersion {
none,
v1,
@@ -54,7 +56,7 @@ FlutterPluginVersion get flutterPluginVersion {
return FlutterPluginVersion.none;
}
String get gradleAppOut {
String getGradleAppOut() {
switch (flutterPluginVersion) {
case FlutterPluginVersion.none:
// Fall through. Pretend we're v1, and just go with it.
@@ -63,12 +65,18 @@ String get gradleAppOut {
case FlutterPluginVersion.managed:
// Fall through. The managed plugin matches plugin v2 for now.
case FlutterPluginVersion.v2:
return '$gradleAppOutDirV2/app.apk';
return '${getGradleAppOutDirV2()}/app.apk';
}
return null;
}
String get gradleAppOutDirV2 {
String getGradleAppOutDirV2() {
_cachedGradleAppOutDirV2 ??= _calculateGradleAppOutDirV2();
return _cachedGradleAppOutDirV2;
}
// Note: this call takes about a second to complete.
String _calculateGradleAppOutDirV2() {
final String gradle = ensureGradle();
ensureLocalProperties();
try {
@@ -224,7 +232,7 @@ Future<Null> buildGradleProjectV2(String gradle, String buildModeName, String ta
if (exitcode != 0)
throwToolExit('Gradle build failed: $exitcode', exitCode: exitcode);
final String buildDirectory = gradleAppOutDirV2;
final String buildDirectory = getGradleAppOutDirV2();
final String apkFilename = 'app-$buildModeName.apk';
final File apkFile = fs.file('$buildDirectory/$apkFilename');
// Copy the APK to app.apk, so `flutter run`, `flutter install`, etc. can find it.