flutter-intellij icon indicating copy to clipboard operation
flutter-intellij copied to clipboard

Running web app from Android Studio is not preserving the last build session

Open vinay-skycliff-it opened this issue 1 year ago • 2 comments

Launch Config for VS Code:

{
            "name": "Flutter-web",
            "request": "launch",
            "type": "dart",
            "program": "lib/main.dart",
            "args": [
                "-d",
                "chrome",
                "--web-port",
                "55586",
                "--web-browser-flag=--disable-web-security"
            ]
        },

Launch Config for Android Studio:

  <configuration default="false" name="main_web" type="FlutterRunConfigurationType" factoryName="Flutter">
    <option name="additionalArgs" value="--debug --web-port=55587 --web-browser-flag=--disable-web-security" />
    <option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
    <method v="2" />
  </configuration>

Issue Description

When running my Flutter web app from VS Code on port 55586, the app resumes from where I left off after being killed and re-run. It preserves all user data, session tokens, and other information unless flutter clean is executed.

However, when running the same app from Android Studio on port 55587, the app creates a fresh instance every time it is killed and re-run. Despite using the same port, user sessions, tokens, and other information are erased.

Version info

• Flutter version 3.22.2 • Dart version 3.4.3 • DevTools version 2.34.3 • Android Studio (version 2024.1) • Flutter IntelliJ plugin version 80.0.2

Expected Behavior

The Flutter web app should preserve the user session, tokens, and other information between runs when using Android Studio, similar to the behavior in VS Code.

vinay-skycliff-it avatar Aug 02 '24 07:08 vinay-skycliff-it

Clone this example project and try running with both Android Studio and VS Code.

vinay-skycliff-it avatar Aug 02 '24 09:08 vinay-skycliff-it

Unfortunately by default it always creates a new user data directory. Theoretically this should do the trick (e.g. in macos): --web-browser-flag=--user-data-dir="$HOME/Library/Application Support/Google/Chrome/Default", but the param is used by flutter first: https://github.com/flutter/flutter/blob/5517cc9b3b3bcf12431b47f495e342a30b738835/packages/flutter_tools/lib/src/web/chrome.dart#L206 which makes it unfunctional.

https://peter.sh/experiments/chromium-command-line-switches/

https://github.com/flutter/flutter-intellij/issues/4767 https://github.com/flutter/flutter-intellij/issues/4974 https://github.com/flutter/flutter-intellij/issues/4767 https://github.com/flutter/flutter/issues/43809 https://github.com/flutter/flutter/issues/79647

Gustl22 avatar Jan 16 '25 10:01 Gustl22