Repository: flutter
Issue: Cannot dump view hierarchy with UiAutomator when using `LiveTestWidgetsFlutterBinding`
Labels: a: tests,platform-android,framework,customer: money (g3),has reproducible steps,P3,found in release: 3.0,found in release: 3.1,team-tool,triaged-tool

This is for an internal use case which inherits from `IntergrationTestWidgetsFlutterBinding` (which inherits from `LiveTestWidgetsFlutterBinding`. See b/236556695 for more context.

With a plain hello flutter app, we can use the following command to dump the view hierarchy on Android using UIAutomator.

```sh
flutter run
```

```sh
# wait for the app to show up, then in another window:
$ adb exec-out uiautomator dump /dev/tty | grep "You have pushed" || echo  "not found"

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><hierarchy rotation="0"><node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="com.example.hello_flutter_no_report_error" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1440,2392]"><node index="0" text="" resource-id="" class="android.widget.LinearLayout" package="com.example.hello_flutter_no_report_error" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1440,2392]"><node index="0" text="" resource-id="android:id/content" class="android.widget.FrameLayout" package="com.example.hello_flutter_no_report_error" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1440,2392]"><node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="com.example.hello_flutter_no_report_error" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1440,2392]"><node index="0" text="" resource-id="" class="android.view.View" package="com.example.hello_flutter_no_report_error" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1440,2392]"><node index="0" text="" resource-id="" class="android.view.View" package="com.example.hello_flutter_no_report_error" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1440,2392]"><node index="0" text="" resource-id="" class="android.view.View" package="com.example.hello_flutter_no_report_error" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1440,2392]"><node index="0" text="" resource-id="" class="android.view.View" package="com.example.hello_flutter_no_report_error" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1440,2392]"><node index="0" text="" resource-id="" class="android.view.View" package="com.example.hello_flutter_no_report_error" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1440,280]"><node index="0" text="" resource-id="" class="android.view.View" package="com.example.hello_flutter_no_report_error" content-desc="Flutter Demo Home Page" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[56,142][847,222]" /></node><node index="1" text="" resource-id="" class="android.view.View" package="com.example.hello_flutter_no_report_error" content-desc="You have pushed the button this many times:" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[232,1238][1208,1294]" /><node index="2" text="" resource-id="" class="android.view.View" package="com.example.hello_flutter_no_report_error" content-desc="0" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[685,1294][755,1434]" /><node NAF="true" index="3" text="" resource-id="" class="android.widget.Button" package="com.example.hello_flutter_no_report_error" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[1188,2140][1384,2336]" /></node></node></node></node></node></node></node><node index="1" text="" resource-id="android:id/statusBarBackground" class="android.view.View" package="com.example.hello_flutter_no_report_error" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1440,84]" /><node index="2" text="" resource-id="android:id/navigationBarBackground" class="android.view.View" package="com.example.hello_flutter_no_report_error" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][0,0]" /></node></hierarchy>UI hierchary dumped to: /dev/tty
```

("You have pushed" is the [text](https://github.com/jiahaog/hello_flutter_integration_test/blob/17fe5c1b5f8b65cb86430b5b0f2261a744d716d5/lib/main.dart#L97) contained in the hello flutter app which we expect to see in the UIAutomator dump)

However, with `LiveTestWidgetsFlutterBinding` as seen in this [minimal repro](https://github.com/jiahaog/hello_flutter_integration_test/commit/3122ca2223f8ab68a74de7424d557f59056a1cae), information about the flutter view hierarchy is no longer returned in the UIAutomator dump.

```sh
$ adb exec-out uiautomator dump /dev/tty | grep "You have pushed" || echo  "not found"
not found
```

Please also see [this commit](https://github.com/jiahaog/hello_flutter_integration_test/commit/120f352f2f397547a4d51d024741aafb68ed1e0e) which is a workaround on top of the above repro with some more information from my debugging which may guide a proper fix. With this workaround, `adb exec-out uiautomator dump /dev/tty | grep "You have pushed" || echo  "not found"` produces the expected output which includes the Flutter view hierarchy.

My Flutter version:

```sh
$ flutter --version
Flutter 3.1.0-0.0.pre.1284 • channel unknown • unknown source
Framework • revision fae31eecce (4 days ago) • 2022-06-16 19:58:05 -0700
Engine • revision f8c0dc87bc
Tools • Dart 2.18.0 (build 2.18.0-189.0.dev) • DevTools 2.14.0
```