【问题标题】:Finished with error: 无法与 Chrome 中的应用程序实例建立连接
【发布时间】:2020-05-09 12:05:29
【问题描述】:

以错误结束:无法与 Chrome 中的应用程序实例。如果 websocket Web 工具使用的连接无法正确建立 连接,例如由于防火墙。

当我在 chrome 浏览器上运行我的 Flutter Web 应用程序时,我收到了这个错误。即使没有解决我的问题,我也关闭了防火墙。

解决此错误的可能解决方案是什么?

我尝试过的临时解决方案:
从开发频道升级到主频道时,我遇到了这个问题。 我为解决这个问题所做的是,清理我的项目的构建缓存(flutter clean),然后使用发布模式运行项目。 之后,我可以在调试模式下运行它。

这暂时解决了我的问题,一段时间后我仍然面临同样的问题。并且实施相同的解决方案并没有解决我的问题。

【问题讨论】:

  • 发布您所面临的错误的完整日志以及flutter doctor 摘要。
  • 是你的杀毒软件吗?
  • 当我错误地使用“flutter run -d Chrome”而不是使用较低 C 的“flutter run -d chrome”运行应用程序时,我遇到了同样的错误

标签: flutter-web


【解决方案1】:

flutter run -d chrome --release

在发布模式下运行是解决这个问题的方法

*这解决了问题,但也使得在运行时无法同时调试您的应用程序

【讨论】:

  • 但是你没有得到任何调试信息。而且热重启也不行。
  • @Joran 使用最新的flutter,您将获得带有--release arg的热重启/重新加载功能。所以暂时不用担心
  • 如果我将此参数添加到 IDE 启动器,我什至看不到日志,这怎么可能?
  • 对于那些使用代理的用户,我解决了这个问题,将 http 和 https 代理设置为 null export http_proxy="" & export https_proxy=""
【解决方案2】:

很高兴您解决了这个问题, 升级版本或更换频道时 运行通常是个好主意 flutter clean 如果需要 flutter pub cache repair; 我认为无需采取任何行动。

【讨论】:

  • 这对我来说是可行的解决方案!谢谢。
【解决方案3】:

使用以下命令:

flutter channel master
flutter create --web
flutter config --enable-web
flutter devices
run -d web
flutter clean
flutter run -d chrome

【讨论】:

    【解决方案4】:

    使用如下命令----->>

    flutter run -d chrome --release
    

    on Editor Android StudioIntellij goto -> Run >> Flutter Run In Release Mode

    这些对我有用

    启用网络---->

    flutter channel beta
    flutter doctor
    flutter config --enable-web (for a ready project) 
    

    flutter create --web 
    

    用于创建项目

    【讨论】:

      【解决方案5】:

      你必须从 chrome 下载 Dart Debug Extension 才能在 web 上运行 Flutter 应用

      【讨论】:

      • 嗯,我第二次尝试了,不确定!
      【解决方案6】:

      使用命令:

      flutter run -d --release
      

      【讨论】:

        【解决方案7】:

        这主要与颤振无关,但是,要么是因为您已将计算机登录到安全模式。

        在我的情况下,shift键卡住了,我不知道我处于安全模式。

        或者您可能需要检查您的防火墙

        • 系统首选项>安全和隐私>>防火墙
        • 点击下面的锁并输入您的系统密码
        • 然后点击防火墙选项enter image description here
        • 在那里添加您的编辑器以允许互联网连接(android studio 或 VsCode)

        看起来像这样:

        https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.macinstruct.com%2Fnode%2F165&psig=AOvVaw060gaYno6OT6j3iRu2WdFK&ust=1605766855994000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCNiv3-y5i-0CFQAAAAAdAAAAABAD

        【讨论】:

          【解决方案8】:

          如果您在找到的设备列表中有 web-server 选项,您可以选择在此处提供代码并点击它提供给您的链接。

          flutter run
          
          Multiple devices found:
          
          Web Server (web) • web-server • web-javascript • Flutter Tools
          Chrome (web)     • chrome     • web-javascript • Google Chrome 87.0.4280.88
          Edge (web)       • edge       • web-javascript • Microsoft Edge 88.0.705.63
          [0]: Web Server (web-server)
          [1]: Chrome (chrome)
          [2]: Edge (edge)
          
          Please choose one (To quit, press "q/Q"): 0
          Running "flutter pub get" in flutter_istack...                   1,417ms
          Launching lib\main.dart on Web Server in debug mode...
          Syncing files to device Web Server...                              39.7s
          lib\main.dart is being served at http://localhost:52569
          

          【讨论】:

            【解决方案9】:

            这个问题的解决方法很简单: 如果您使用的是 VS 代码:

            1. 转到扩展市场
            2. 搜索“Chrome 调试器”
            3. 安装它并重新启动您的 IDE 并享受吧!

            如果您使用的是 Android Studio,请在 Android Studio 的市场中下载相同的扩展程序/插件。

            这个插件将有助于在 Chrome 中建立与应用程序实例的连接。 因此它将在调试模式下运行颤振网络。 为我工作,我希望它也适合你!

            【讨论】:

              【解决方案10】:

              我第一次想运行网络应用程序时遇到了同样的问题,但是当我重新运行网络应用程序时,它工作正常。 尝试重新运行

              【讨论】:

              • @sanaa-al-ahdal 是正确的,但有时它不起作用
              • @victcdva 呃,我不知道,但是我从第一次运行时总是会遇到这个问题,当我重新运行该应用程序时,它运行良好,但仍然不知道为什么会这样继续发生
              【解决方案11】:

              我使用这两个命令解决了这个错误,

              1. 首先运行这个命令flutter clean
              2. 清理后运行此命令flutter pub cache repair

              修复后,你在网页上启动 Flutter 应用,它会问一个问题, To hot restart changes while running, press "r" or "R". 所以按r热重启也启用, 快乐编码

              【讨论】:

                【解决方案12】:

                我也遇到过这个问题。我第一次运行“flutter run -d chrome”时总是出现这个错误,但是如果我第二次再次运行它,它会完美运行。

                【讨论】:

                  【解决方案13】:

                  在 Flutter beta 通道的 Windows 中使用 VSCode 时,使用命令 flutter run -d chrome 在 Chrome 中运行而不是 F5。
                  每次都对我有用。

                  【讨论】:

                  • 我运行它 使用 flutter run -d chrome 并得到错误,所以我不知道这是否有帮助
                  【解决方案14】:

                  这就是我所做的:

                  • 关闭防病毒软件
                  • flutter run -d Chrome

                  如果你仍然有错误,因为我有,所以我也这样做:

                  • 更改为测试版
                  • 重新加载窗口
                  • 重新创建到新项目
                  • flutter create .
                  • flutter run -d Chrome

                  如果仍然出现错误:无法编译应用程序无法编译 Web 应用程序 运行flutter upgrade 然后重新加载窗口 然后运行flutter run -d Chrome

                  为我工作。

                  【讨论】:

                    【解决方案15】:

                    $flutter clean 它将删除飞镖和构建文件夹

                    $flutter pub缓存修复

                    它会像这样更新包列表

                    Downloading _discoveryapis_commons 0.1.9...
                    Downloading _fe_analyzer_shared 1.0.3...
                    Downloading analyzer 0.38.5...
                    Downloading analyzer 0.39.4...
                    Downloading analyzer_plugin 0.2.1...
                    Downloading archive 2.0.11...
                    Downloading args 1.5.2...
                    Downloading assets_audio_player 1.2.3...
                    Downloading async 2.4.0...
                    Downloading audioplayer 0.5.2...
                    Downloading audioplayers 0.14.0...
                    Downloading battery 0.3.1+4...
                    Downloading bazel_worker 0.1.23...
                    Downloading bazel_worker 0.1.23+1...
                    Downloading boolean_selector 1.0.5...
                    Downloading browser_launcher 0.1.5...
                    Downloading build 1.2.1...
                    Downloading build 1.2.2...
                    Downloading build_config 0.4.1+1...
                    Downloading build_config 0.4.2...
                    Downloading build_daemon 2.1.0...
                    Downloading build_daemon 2.1.3...
                    Downloading build_modules 2.6.3...
                    Downloading build_modules 2.7.0...
                    Downloading build_modules 2.8.0...
                    Downloading build_modules 2.8.1...
                    Downloading build_resolvers 1.2.1...
                    Downloading build_resolvers 1.3.1...
                    Downloading build_resolvers 1.3.2...
                    Downloading build_resolvers 1.3.3...
                    Downloading build_runner 1.7.2...
                    Downloading build_runner 1.7.3...
                    Downloading build_runner 1.7.4...
                    Downloading build_runner_core 4.1.0...
                    Downloading build_runner_core 4.3.0...
                    Downloading build_runner_core 4.4.0...
                    Downloading build_test 0.10.9+1...
                    Downloading build_test 0.10.12...
                    Downloading build_test 0.10.12+1...
                    Downloading build_vm_compilers 1.0.4...
                    Downloading build_web_compilers 2.7.1...
                    Downloading build_web_compilers 2.8.0...
                    Downloading build_web_compilers 2.9.0...
                    Downloading built_collection 4.2.2...
                    Downloading built_collection 4.3.2...
                    Downloading built_value 6.8.2...
                    Downloading built_value 7.0.8...
                    Downloading built_value 7.0.9...
                    Downloading built_value_generator 6.8.2...
                    Downloading charcode 1.1.2...
                    Downloading charcode 1.1.3...
                    Downloading checked_yaml 1.0.2...
                    Downloading code_builder 3.2.0...
                    Downloading code_builder 3.2.1...
                    Downloading collection 1.14.11...
                    Downloading collection 1.14.12...
                    Downloading completion 0.2.1+1...
                    Downloading completion 0.2.2...
                    Downloading connectivity 0.4.5+3...
                    Downloading convert 2.1.1...
                    Downloading coverage 0.13.3+1...
                    Downloading coverage 0.13.3+3...
                    Downloading coverage 0.13.4...
                    Downloading coverage 0.13.6...
                    Downloading crypto 2.1.3...
                    Downloading crypto 2.1.4...
                    Downloading csslib 0.16.1...
                    Downloading cupertino_icons 0.1.2...
                    Downloading cupertino_icons 0.1.3...
                    Downloading dart_style 1.3.3...
                    Downloading device_info 0.4.1+1...
                    Downloading devtools 0.1.8-dev.1...
                    Downloading devtools 0.1.11...
                    Downloading devtools 0.1.15...
                    Downloading devtools_server 0.1.9...
                    Downloading devtools_server 0.1.12...
                    Downloading devtools_server 0.1.13...
                    Downloading dwds 0.7.9...
                    Downloading dwds 0.8.5...
                    Downloading dwds 1.0.1...
                    Downloading e2e 0.2.1+1...
                    Downloading file 5.1.0...
                    Downloading file_testing 2.1.0...
                    Downloading fixnum 0.10.11...
                    Downloading flutter_gallery_assets 0.1.9+2...
                    Downloading font_awesome_flutter 8.7.0...
                    Downloading front_end 0.1.27...
                    Downloading glob 1.2.0...
                    Downloading googleapis 0.54.0...
                    Downloading googleapis_auth 0.2.10...
                    Downloading graphs 0.2.0...
                    Downloading html 0.14.0+3...
                    Downloading http 0.12.0+2...
                    Downloading http 0.12.0+4...
                    Downloading http_multi_server 2.1.0...
                    Downloading http_multi_server 2.2.0...
                    Downloading http_parser 3.1.3...
                    Downloading image 2.1.4...
                    Downloading intl 0.16.0...
                    Downloading intl 0.16.1...
                    Downloading intl_translation 0.17.7...
                    Downloading io 0.3.3...
                    Downloading isolate 2.0.2...
                    Downloading js 0.6.1+1...
                    Downloading json_annotation 3.0.0...
                    Downloading json_annotation 3.0.1...
                    Downloading json_rpc_2 2.1.0...
                    Downloading kernel 0.3.27...
                    Downloading linter 0.1.101...
                    Downloading logging 0.11.3+2...
                    Downloading logging 0.11.4...
                    Downloading matcher 0.12.6...
                    Downloading meta 1.1.8...
                    Downloading mime 0.9.6+3...
                    Downloading mockito 4.1.1...
                    Downloading multi_server_socket 1.0.2...
                    Downloading multicast_dns 0.2.2...
                    Downloading mustache 1.1.1...
                    Downloading native_stack_traces 0.2.2...
                    Downloading node_interop 1.0.3...
                    Downloading node_io 1.0.1+2...
                    Downloading node_preamble 1.4.8...
                    Downloading package_config 1.1.0...
                    Downloading package_resolver 1.0.10...
                    Downloading path 1.6.4...
                    Downloading path_provider 1.4.2...
                    Downloading path_provider 1.6.1...
                    Downloading pedantic 1.8.0+1...
                    Downloading pedantic 1.9.0...
                    Downloading petitparser 2.4.0...
                    Downloading platform 2.2.1...
                    Downloading plugin 0.2.0+3...
                    Downloading pool 1.4.0...
                    Downloading process 3.0.12...
                    Downloading protobuf 1.0.1...
                    Downloading pub_semver 1.4.2...
                    Downloading pub_semver 1.4.3...
                    Downloading pubspec_parse 0.1.5...
                    Downloading quiver 2.0.5...
                    Downloading quiver 2.1.2+1...
                    Downloading rxdart 0.23.1...
                    Downloading scoped_model 1.0.1...
                    Downloading scratch_space 0.0.4+1...
                    Downloading scratch_space 0.0.4+2...
                    Downloading shelf 0.7.5...
                    Downloading shelf_packages_handler 1.0.4...
                    Downloading shelf_proxy 0.1.0+7...
                    Downloading shelf_static 0.2.8...
                    Downloading shelf_web_socket 0.2.3...
                    Downloading shrine_images 1.1.2...
                    Downloading source_gen 0.9.4+6...
                    Downloading source_map_stack_trace 1.1.5...
                    Downloading source_maps 0.10.8...
                    Downloading source_maps 0.10.9...
                    Downloading source_span 1.5.5...
                    Downloading source_span 1.6.0...
                    Downloading sse 2.1.2...
                    Downloading sse 3.1.1...
                    Downloading sse 3.1.2...
                    Downloading stack_trace 1.9.3...
                    Downloading stream_channel 2.0.0...
                    Downloading stream_transform 0.0.20...
                    Downloading stream_transform 1.1.0...
                    Downloading string_scanner 1.0.5...
                    Downloading sync_http 0.1.4...
                    Downloading sync_http 0.2.0...
                    Downloading term_glyph 1.1.0...
                    Downloading test 1.9.4...
                    Downloading test 1.12.0...
                    Downloading test_api 0.2.11...
                    Downloading test_api 0.2.14...
                    Downloading test_core 0.2.15...
                    Downloading test_core 0.3.0...
                    Downloading timing 0.1.1+2...
                    Downloading typed_data 1.1.6...
                    Downloading url_launcher 5.2.5...
                    Downloading url_launcher_platform_interface 1.0.1...
                    Downloading usage 3.4.1...
                    Downloading uuid 2.0.2...
                    Downloading uuid 2.0.4...
                    Downloading vector_math 2.0.8...
                    Downloading video_player 0.10.2+5...
                    Downloading vm_service 1.2.0...
                    Downloading vm_service_client 0.2.6+2...
                    Downloading watcher 0.9.7+12...
                    Downloading watcher 0.9.7+13...
                    Downloading web_socket_channel 1.1.0...
                    Downloading webdev 2.5.4...
                    Downloading webdriver 2.1.1...
                    Downloading webdriver 2.1.2...
                    Downloading webkit_inspection_protocol 0.5.0...
                    Downloading xml 3.5.0...
                    Downloading yaml 2.2.0...
                    Reinstalled 194 packages.
                    Reactivating webdev 2.5.4...
                    Precompiling executables...
                    Precompiled webdev:webdev.
                    Installed executable webdev.
                    

                    如果你想创建一个测试网络应用程序运行这个 $flutter create myApp(你的应用名)

                    如果您已经有一个项目并且想要为该包添加 Web 支持,请运行 $颤振创建。

                    打开您的 pubspec.yaml 文件 在 dev_dependencies 下添加以下 build_runner 和其他三个值

                    然后在顶部运行 packages get 命令。

                    build_runner: ^1.7.2
                    build_test: ^0.10.12
                    build_web_compilers: ^2.7.1
                    

                    重启IDE并使用检查web配置是否为真

                    `````$flutter config
                    
                    Settings:
                    android-sdk: e:\android\sdk
                    enable-web: true
                    

                    分析报告目前已启用。

                    一旦为真,如果您想使用 chrome 进行调试,请运行以下命令

                    $flutter run -d chrome

                    【讨论】:

                      【解决方案16】:

                      您可以运行以下命令:

                      flutter channel beta
                      
                      flutter doctor
                      
                      flutter config --enable-web
                      

                      然后重启你的windows和下一步:

                      flutter create --web
                      

                      用于创建项目。或者你可以使用这个命令:

                      flutter run -d --release
                      

                      实际上第一步对我有用:)

                      【讨论】:

                        【解决方案17】:

                        web目录下的index.html文件可能有错误。

                        就我而言,我使用的是 firebase-messaging-sw.js(服务工作者)

                        评论后它起作用了。

                        【讨论】:

                          【解决方案18】:

                          尝试以相同的顺序运行以下命令:

                          flutter clean
                          
                          flutter pub cache repair
                          
                          flutter run --verbose -d chrome
                          

                          这对我有用。

                          【讨论】:

                            【解决方案19】:

                            设置:

                            1. 运行以下命令以使用最新版本的 Flutter SDK:

                              • flutter 通道稳定
                              • 颤振升级
                            2. 要在 Chrome 中从 localhost 提供您的应用程序,请在包顶部输入以下内容:

                              • flutter run -d chrome

                            【讨论】:

                            • 等等,这如何回答这个问题?
                            猜你喜欢
                            • 2020-08-02
                            • 2018-04-27
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            相关资源
                            最近更新 更多