Skip to content

[Android] Hang on Splash Screen following process restoration when run via VSCode #4956

Closed

Description

@btrautmann

Describe the bug

We've been triaging some Android issues related to process restoration and have bumped into this bug enough times that I think a ticket is warranted. I have found one or two related issues (namely #3525) but none of them seem to mention process restoration.

To Reproduce

⚠️ NOTE: I created this repo for reproducing (basically a simple flutter create -e, but allows all commands below to succeed automatically).

Steps to reproduce the behavior:

  1. flutter create -e restoration_bug
  2. cd restoration_bug
  3. Open main.dart and make sure an Android device is selected. We've found this reproduces 100% on Android 14 devices, but have not tested much outside that. Will test a variety of OS versions and report back via comments.
  4. On your device, enable developer options and set the Background process limit to No background processes (this will just help to have the system kill the process sooner than it normally would)
  5. Run the app via the Run button on the main function
  6. Background the app and run other apps until Android kills the Flutter process. You can be sure it is killed by running adb shell pidof com.example.restoration_bug and verifying there is NO output. If output exists, the app is still running under that process ID.
  7. Once output of above command is clear, open the app back up via Recents or from Home Screen Launcher.
  8. Note that the app never progresses beyond the Splash Screen which shows the Flutter logo.

Why do I believe this is related to the Code extension?

  1. This does not happen when ran via flutter run
  2. This does not happen once the app is manually quit (via a swipe up on Recents), regardless of how it was run.

Expected behavior
The app should land on the initial route which shows a Hello world message.

Screenshots

This video shows how restoration behaves when run from VSCode and then when run after quitting the app:

Screen.Recording.2024-01-23.at.13.01.32.mov

Dart: Collect Diagnostic Information:

Note that while this sample is using an older version of Flutter, I've tested this on newer versions (3.16.4) with the same result.

Workspace Environment
Dart Code extension: 3.80.0
Flutter extension: 3.80.0 (activated)

App: Visual Studio Code
App Host: desktop
Version: mac 1.85.2

Workspace type: Flutter (LSP)

Dart (3.0.7): /Users/brandontrautmann/fvm/versions/3.10.7/bin/cache/dart-sdk
Flutter (3.10.7): /Users/brandontrautmann/fvm/versions/3.10.7 (sdk gphone64 arm64 (android-arm64/android))

Output from 'dart info'

/Users/brandontrautmann/fvm/versions/3.10.7/bin/cache/dart-sdk/bin/dart info

If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.

General info

  • Dart 3.0.7 (stable) (Mon Jul 24 13:17:56 2023 +0000) on "macos_arm64"
  • on macos / Version 14.2.1 (Build 23C71)
  • locale is en-US

Project info

  • sdk constraint: '>=3.0.7 <4.0.0'
  • dependencies: flutter
  • dev_dependencies: flutter_lints, flutter_test

Process info

Memory CPU Elapsed time Command line
9 MB 0.0% 01:33:24 dart devtools --machine --allow-embedding
18 MB 0.0% 01:31:54 dart devtools --machine --allow-embedding
23 MB 0.0% 01:23:34 dart devtools --machine --allow-embedding
23 MB 0.0% 46:22 dart devtools --machine --allow-embedding
45 MB 0.0% 07:35 dart devtools --machine --allow-embedding
24 MB 0.0% 01:33:24 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.80.0
24 MB 0.0% 01:31:54 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.80.0
40 MB 0.0% 01:23:34 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.80.0
39 MB 0.0% 46:22 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.80.0
240 MB 0.0% 07:35 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.80.0
41 MB 0.3% 01:33:24 flutter_tools.snapshot daemon
49 MB 0.5% 01:31:54 flutter_tools.snapshot daemon
54 MB 0.5% 01:23:34 flutter_tools.snapshot daemon
59 MB 0.1% 46:22 flutter_tools.snapshot daemon
59 MB 0.2% 07:35 flutter_tools.snapshot daemon
22 MB 0.0% 01:27:06 flutter_tools.snapshot debug_adapter
30 MB 0.0% 01:27:04 flutter_tools.snapshot run --machine --start-paused -d 0492C672-A151-402C-AAA0-0B694038CF37 --devtools-server-address http:/ --target /main.dart
24 MB 0.0% 01:27:00 frontend_server.dart.snapshot --sdk-root / --incremental --target=flutter --experimental-emit-debug-metadata -DFLUTTER_WEB_AUTO_DETECT=true -DFLUTTER_WEB_CANVASKIT_URL=https:/ --output-dill /app.dill --packages /package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts --track-widget-creation --filesystem-scheme org-dartlang-root --initialize-from-dill build/59906ac2072ea23d943f4334a0ae780f.cache.dill.track.dill --verbosity=error --enable-experiment=alternative-invalidation-strategy
Output from 'flutter doctor'

/Users/brandontrautmann/fvm/versions/3.10.7/bin/flutter doctor -v

[!] Flutter (Channel unknown, 3.10.7, on macOS 14.2.1 23C71 darwin-arm64, locale en-US)
    ! Flutter version 3.10.7 on channel unknown at /Users/brandontrautmann/fvm/versions/3.10.7
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    ! Unknown upstream repository.
      Reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    • Framework revision e285328a69 (5 months ago), 2023-08-17 17:55:17 -0700
    • Engine revision 077a732ef4
    • Dart version 3.0.7
    • DevTools version 2.23.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/brandontrautmann/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_SDK_ROOT = /Users/brandontrautmann/Library/Android/sdk
    • Java binary at: /Users/brandontrautmann/.jenv/shims/java
    • Java version OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] IntelliJ IDEA Community Edition (version 2023.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.85.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.80.0

[✓] Connected device (5 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554                        • android-arm64  • Android 14 (API 34) (emulator)
    • Brandon’s iPhone (mobile)   • redacted • ios                       • iOS 17.3 21D50
    • iPhone 13 mini (mobile)     • redacted • ios                       • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)             • macos                                • darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
    • Chrome (web)                • chrome                               • web-javascript • Google Chrome 120.0.6099.234

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Activity

  1. btrautmann commented on Jan 23, 2024

    @btrautmann
    Author

    Update: I was able to reproduce this on a physical device (Motox4) running Android 9, so it's safe (I think) to say it's not device/OS specific.

  2. btrautmann commented on Jan 23, 2024

    @btrautmann
    Author

    Please let me know if I can capture any more logs/information, happy to help in any way possible!

  3. DanTup commented on Jan 24, 2024

    @DanTup
    Member

    I suspect this is unrelated to the VS Code extension as Flutter abstracts all device-specific things away. It's possible that it's triggered by something different that we do compared to running from the terminal though (for example starting the application paused so we can attach a debugger).

    I'll see if I can repro though to see if I can narrow down what might be happening.

  4. added
    in flutterRelates to running Flutter apps
    in debuggingRelates to the debug adapter or process of running debug sessions
    on Jan 24, 2024
  5. DanTup commented on Jan 24, 2024

    @DanTup
    Member

    It appears that this is indeed happening because of --start-paused.

    I was able to reproduce the issue, so I ran:

    adb logcat | select-string "[fF]lutter|[Dd]art"
    

    Then I reproduce the issue. When I tried to switch back the the application I saw in the logcat output that the app started up and printing its VM Service URL:

    01-24 15:21:31.449 19400 19528 I flutter : The Dart VM service is listening on http://127.0.0.1:43061/j5aQAu7eeog=/
    

    I connected to this using the Debug: Attach to Flutter Process command and pasted in that URL. It showed that the app was paused, and clicking the Resume (play) button on the debug toolbar caused the app to load as normal and show "Hello World!".

    What I don't understand though, is why this doesn't matter if you terminate the app and then re-launch it normally... in that case, it seems to not start paused like that. I wonder if "restoring" the app takes a different path to a clean start.

    This is probably something that needs input from the Flutter team - I would suggest filing an issue in flutter/flutter and CCing me (and linking here) and perhaps someone that is more familiar with how this works can help.

  6. DanTup commented on Jan 24, 2024

    @DanTup
    Member

    Here's a way to reproduce without VS Code:

    • Run the app with the --start-paused flag (eg. flutter run -d 33aa --start-paused)
    • The app will start paused
    • Click the link in the "The Flutter DevTools debugger and profiler is available...." output from flutter run to open DevTools
    • Click the "Resume" button to unpause the app and have it start
    • Repeat the other steps to get the app terminated in the background
    • Switch back to the app from the recents

    You'll see the same thing, the app will be paused at startup and not launch correctly.

  7. btrautmann commented on Jan 24, 2024

    @btrautmann
    Author

    @DanTup thanks for the quick and thorough response! I'll open an issue in flutter/flutter, link to this one, and close this one once that's done.

  8. btrautmann commented on Jan 24, 2024

    @btrautmann
    Author

    Closing in favor of flutter/flutter#142149.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in debuggingRelates to the debug adapter or process of running debug sessionsin flutterRelates to running Flutter appsis bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions