A bunch of onboarding error detections (#12977)

diff --git a/packages/flutter_tools/lib/src/ios/code_signing.dart b/packages/flutter_tools/lib/src/ios/code_signing.dart
index 647015a..aaacedb 100644
--- a/packages/flutter_tools/lib/src/ios/code_signing.dart
+++ b/packages/flutter_tools/lib/src/ios/code_signing.dart
@@ -41,6 +41,9 @@
 team by:
 $fixWithDevelopmentTeamInstruction
 
+It's also possible that a previously installed app with the same Bundle Identifier was
+signed with a different certificate.
+
 For more information, please visit:
   https://flutter.io/setup/#deploy-to-ios-devices
 
@@ -65,8 +68,11 @@
        open ios/Runner.xcworkspace
   2- Select the 'Runner' project in the navigator then the 'Runner' target
      in the project settings
-  3- In the 'General' tab, make sure a 'Development Team' is selected. You may need to add
-     your Apple ID first.
+  3- In the 'General' tab, make sure a 'Development Team' is selected. You may need to
+         - Log in with your Apple ID in Xcode first
+         - Ensure you have a valid unique Bundle ID
+         - Register your device with your Apple Developer Account
+         - Let Xcode automatically provision a profile for your app
   4- Build or run your project again''';
 
 final RegExp _securityFindIdentityDeveloperIdentityExtractionPattern =
diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart
index 8dc8e18..e79da6d 100644
--- a/packages/flutter_tools/lib/src/ios/devices.dart
+++ b/packages/flutter_tools/lib/src/ios/devices.dart
@@ -16,6 +16,7 @@
 import '../device.dart';
 import '../globals.dart';
 import '../protocol_discovery.dart';
+import 'code_signing.dart';
 import 'ios_workflow.dart';
 import 'mac.dart';
 
@@ -242,7 +243,11 @@
     if (!debuggingOptions.debuggingEnabled) {
       // If debugging is not enabled, just launch the application and continue.
       printTrace('Debugging is not enabled');
-      installationResult = await runCommandAndStreamOutput(launchCommand, trace: true);
+      installationResult = await runCommandAndStreamOutput(
+        launchCommand,
+        mapFunction: monitorInstallationFailure,
+        trace: true,
+      );
     } else {
       // Debugging is enabled, look for the observatory server port post launch.
       printTrace('Debugging is enabled, connecting to observatory');
@@ -254,7 +259,11 @@
 
       final Future<Uri> forwardObservatoryUri = observatoryDiscovery.uri;
 
-      final Future<int> launch = runCommandAndStreamOutput(launchCommand, trace: true);
+      final Future<int> launch = runCommandAndStreamOutput(
+        launchCommand,
+        mapFunction: monitorInstallationFailure,
+        trace: true,
+      );
 
       localObservatoryUri = await launch.then<Uri>((int result) async {
         installationResult = result;
@@ -331,6 +340,33 @@
 
   @override
   Future<Null> takeScreenshot(File outputFile) => iMobileDevice.takeScreenshot(outputFile);
+
+  // Maps stdout line stream. Must return original line.
+  String monitorInstallationFailure(String stdout) {
+    // Installation issues.
+    if (stdout.contains('Error 0xe8008015') || stdout.contains('Error 0xe8000067')) {
+      printError(noProvisioningProfileInstruction, emphasis: true);
+
+    // Launch issues.
+    } else if (stdout.contains('e80000e2')) {
+      printError('''
+═══════════════════════════════════════════════════════════════════════════════════
+Your device is locked. Unlock your device first before running.
+═══════════════════════════════════════════════════════════════════════════════════''',
+      emphasis: true);
+    } else if (stdout.contains('Error 0xe8000022')) {
+      printError('''
+═══════════════════════════════════════════════════════════════════════════════════
+Error launching app. Try launching from within Xcode via:
+    open ios/Runner.xcworkspace
+
+Your Xcode version may be too old for your iOS version.
+═══════════════════════════════════════════════════════════════════════════════════''',
+      emphasis: true);
+    }
+
+    return stdout;
+  }
 }
 
 class _IOSDeviceLogReader extends DeviceLogReader {
diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart
index 601edd3..644f66a 100644
--- a/packages/flutter_tools/lib/src/ios/mac.dart
+++ b/packages/flutter_tools/lib/src/ios/mac.dart
@@ -354,11 +354,9 @@
 Future<Null> diagnoseXcodeBuildFailure(XcodeBuildResult result, BuildableIOSApp app) async {
   if (result.xcodeBuildExecution != null &&
       result.xcodeBuildExecution.buildForPhysicalDevice &&
-      ((result.stdout?.contains('BCEROR') == true &&
-          // May need updating if Xcode changes its outputs.
-          result.stdout?.contains('Xcode couldn\'t find a provisioning profile matching') == true)
-          // Error message from ios-deploy for missing provisioning profile.
-          || result.stdout?.contains('0xe8008015') == true)) {
+      result.stdout?.contains('BCEROR') == true &&
+      // May need updating if Xcode changes its outputs.
+      result.stdout?.contains('Xcode couldn\'t find a provisioning profile matching') == true) {
     printError(noProvisioningProfileInstruction, emphasis: true);
     return;
   }