Repository: flutter
Issue: FlutterError.reportError is not printed in the logcat when installing the APK manually
Labels: platform-android,a: error message,has reproducible steps,P2,found in release: 3.0,found in release: 3.1,team-android,triaged-android



## Steps to Reproduce

With the hello flutter app:

```dart
import 'package:flutter/material.dart';

void main() {
  // Initializing the binding overrides FlutterError.presentError.
  // See https://github.com/flutter/flutter/blob/f6f0d608bac344c113481e59219f69879b208e48/packages/flutter/lib/src/widgets/widget_inspector.dart#L991-L993
  WidgetsFlutterBinding.ensureInitialized();

  FlutterError.reportError(
    FlutterErrorDetails(exception: AssertionError('foo')),
  );
  runApp(const MyApp());
}

// ...
```

The error is printed with `flutter run` on an Android emulator:

```
$ flutter run
Using hardware rendering with device sdk gphone x86 arm. If you notice graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib/main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...                              7.7s
✓  Built build/app/outputs/flutter-apk/app-debug.apk.
Installing build/app/outputs/flutter-apk/app.apk...                 4.8s
Syncing files to device sdk gphone x86 arm...                      142ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

💪 Running with sound null safety 💪

An Observatory debugger and profiler on sdk gphone x86 arm is available at: http://127.0.0.1:60824/HmQHeq1fxVY=/

══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════
The following assertion was thrown:
Assertion failed: "foo"
════════════════════════════════════════════════════════════════════════════════════════════════════
The Flutter DevTools debugger and profiler on sdk gphone x86 arm is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:60824/HmQHeq1fxVY=/
```

But when I manually install the APK and run it, the error does not appear in the logcat:

```
$ adb uninstall com.example.hello_flutter_no_report_error
Success

$ adb install build/app/outputs/flutter-apk/app-debug.apk
Performing Streamed Install
Success

# Start the app
$ adb shell am start com.example.hello_flutter_no_report_error/com.example.hello_flutter_no_report_error.MainActivity
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.hello_flutter_no_report_error/.MainActivity }
```

The assertion error does not show up in `adb logcat`.


## Possible Cause

This is likely happening because of `isStructuredErrorsEnabled`:

https://github.com/flutter/flutter/blob/f6f0d608bac344c113481e59219f69879b208e48/packages/flutter/lib/src/widgets/widget_inspector.dart#L969-L979

The `flutter.inspector.structuredErrors` constant flag is likely not set when using `flutter build apk --debug` and defaults to `true` on Android.

This results in `FlutterError.presentError` being overriden with `_reportStructuredError`

https://github.com/flutter/flutter/blob/f6f0d608bac344c113481e59219f69879b208e48/packages/flutter/lib/src/widgets/widget_inspector.dart#L991-L993

`_reportStructuredError` sends errors to `developer.postEvent`:

https://github.com/flutter/flutter/blob/f6f0d608bac344c113481e59219f69879b208e48/packages/flutter/lib/src/widgets/widget_inspector.dart#L953

But I don't think `developer.postEvent` is wired up to stdout of the app.

I'm missing some context behind the functionality here, perhaps `flutter.inspector.structuredErrors` should default to false instead and only be enabled by supporting tools so the APK can work on its own. Internally, there are use cases where the APK is built separately and executed without the Flutter tool. (See also http://shortn/_fVpZ7QSo3P)