Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flatter web应用程序缺少firebase.json并显示;欢迎Firebase主机安装完成”;部署到firebase主机时_Firebase_Flutter_Flutter Web_Firebase Hosting - Fatal编程技术网

Flatter web应用程序缺少firebase.json并显示;欢迎Firebase主机安装完成”;部署到firebase主机时

Flatter web应用程序缺少firebase.json并显示;欢迎Firebase主机安装完成”;部署到firebase主机时,firebase,flutter,flutter-web,firebase-hosting,Firebase,Flutter,Flutter Web,Firebase Hosting,背景 我正在使用Android Studio创建一个Flitter web应用程序 该应用程序在Google Chrome的localhost上成功运行 当我将其部署到Firebase hosting时,会显示“Firebase hosting Setup Complete”页面,而不是应用程序 我尝试过的 有几个堆栈溢出帖子尚未解决此问题。这些措施包括: 遵循的步骤 在Android Studio中,创建一个新的颤振应用程序 我使用包名au.com.mydomain(其中

背景

  • 我正在使用Android Studio创建一个Flitter web应用程序
  • 该应用程序在Google Chrome的localhost上成功运行
  • 当我将其部署到Firebase hosting时,会显示“Firebase hosting Setup Complete”页面,而不是应用程序
我尝试过的 有几个堆栈溢出帖子尚未解决此问题。这些措施包括:

遵循的步骤

  • 在Android Studio中,创建一个新的颤振应用程序
  • 我使用包名
    au.com.mydomain
    (其中
    mydomain
    是我拥有的域名)
  • 我注意到项目文件结构中没有Web文件夹
  • 我打开一个终端窗口并导航到应用程序的根文件夹
  • 我运行命令
    flattercreateweb
  • 该命令的结果是“全部完成!”和“要运行应用程序,请键入
    cd-web
    flatter-run
  • 我执行命令
    cd-web
    flatter-run
    。该应用程序在Google Chrome的localhost上成功运行
  • 我回到Android Studio,注意到项目文件结构中仍然没有Web文件夹
  • 我使用web浏览器导航到Firebase并创建一个新项目,我称之为
    demo159752
  • 我禁用此项目的谷歌分析
  • 项目已成功创建
  • 在Firebase中的demo159752项目中,我添加了一个Web应用程序
  • 我使用
    demo
    作为应用程序的昵称
  • 我没有选中“还设置Firebase主机…”框
  • 我点击注册应用程序按钮
  • 我阅读了说明,其中指出我应该“在使用任何Firebase服务之前,将这些脚本复制并粘贴到标记的底部”
  • 我回到Android Studio来做这件事,并注意到Android Studio中的文件结构中现在可以看到一个
    web
    文件夹
  • 我打开这个
    web
    文件夹。它不包含index.html文件,但包含一个子文件夹,也称为
    web
  • 我打开
    web
    子文件夹,发现它包含一个index.html文件
  • 我打开index.html文件并导航到
    。我将firebase中的代码粘贴到
    的正上方
  • 我在web浏览器中返回Firebase并单击“继续”进入控制台
  • 在Firebase控制台中,我单击主机
  • 我单击Get Started(开始)并升级为运行
    npm install-g firebase tools
    以安装firebase CLI。它已经安装在我的机器上,但我还是从终端运行此命令。这将导致“更新1包”的声明
  • 我在web浏览器中返回Firebase。我没有单击名为“还显示将Firebase JavaScript SDK添加到我的web应用程序的步骤”的选项,而是继续执行步骤2
  • 我被指示运行命令
    firebase login
    ,我就是这么做的。这导致声明:“已作为
    电子邮件地址
    登录”(其中
    电子邮件地址
    是我的电子邮件地址)
  • 我返回浏览器,并被指示运行命令
    firebase init
    ,我这样做了。然后我导航到托管选项,按键盘上的空格键选择它,然后按enter键
  • 有人问我要使用哪个firebase项目,我选择了
    demo159752
  • 我使用以下选项:
  • 您想使用什么作为公用目录<代码>构建/网络
  • 配置为单页应用程序<代码>Y
  • 使用GitHub设置自动构建和部署<代码>N
  • 我注意到这句话:
    ✔  编写build/web/index.html
  • 我注意到以下语句:
    I正在将配置信息写入firebase.json…
  • 我注意到这样一句话:
    I正在将项目信息写入.firebaserc…
  • 我注意到这句话:
    ✔  Firebase初始化完成
  • 我在web浏览器中返回Firebase并单击“下一步”继续执行步骤3
  • 我被指示运行命令
    firebase deploy
  • 我返回终端窗口并运行此命令
  • 我注意到这句话:
    ✔  部署完成!并获得一个托管URL。
  • 我导航到托管URL,希望看到我的应用程序。然而,我只看到一个页面,上面写着“Firebase主机安装完成”
  • 我返回Android Studio并检查
    firebase.json
    文件是否已按预期创建。然而,事实并非如此
  • 我试图通过手动创建
    firebase.json
    文件来解决这个问题。为此,我在根目录中创建了一个名为
    firebase.json的新文件,并使用以下代码:
{“托管”:{ “公共”:“构建/网络”, “忽略”:[ “firebase.json”, “/.*”, “/node\u模块/**” ]}}

  • 我返回终端并导航到项目的根目录,然后进入web子文件夹,然后运行
    flatterbuildweb--release
  • 然后运行
    firebase部署
  • 应用程序仍未部署,Firebase主机安装完成页面仍保留
问题 为什么我的应用程序部署不成功?我做错了什么?我需要做什么才能成功部署它

其他详细信息 颤振版本:

Flutter 2.1.0-12.1.pre • channel dev • https://github.com/flutter/flutter.git
Framework • revision 8264cb3e8a (5 weeks ago) • 2021-03-10 12:37:57 -0800
Engine • revision 711ab3fda0
Tools • Dart 2.13.0 (build 2.13.0-116.0.dev)
颤振医生

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, 2.1.0-12.1.pre, on Mac OS X 10.15.7 19H524 darwin-x64,
    locale en-AU)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for
      more details.
[!] Xcode - develop for iOS and macOS
    ✗ Xcode 11.4.1 out of date (12.0.1 is recommended).
      Download the latest version or update via the Mac App Store.
    ! CocoaPods 1.9.3 out of date (1.10.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin
        code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade see
      https://guides.cocoapods.org/using/getting-started.html#installation for
      instructions.
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] Connected device (1 available)

! Doctor found issues in 2 categories.
index.html文件

<!DOCTYPE html>
<html>
<head>
  <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    For more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
  -->
  <base href="/">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter project.">

  <!-- iOS meta tags & icons -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="web">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <title>web</title>
  <link rel="manifest" href="manifest.json">
</head>
<body>
  <!-- This script installs service_worker.js to provide PWA functionality to
       application. For more information, see:
       https://developers.google.com/web/fundamentals/primers/service-workers -->
  <script>
    var serviceWorkerVersion = null;
    var scriptLoaded = false;
    function loadMainDartJs() {
      if (scriptLoaded) {
        return;
      }
      scriptLoaded = true;
      var scriptTag = document.createElement('script');
      scriptTag.src = 'main.dart.js';
      scriptTag.type = 'application/javascript';
      document.body.append(scriptTag);
    }

    if ('serviceWorker' in navigator) {
      // Service workers are supported. Use them.
      window.addEventListener('load', function () {
        // Wait for registration to finish before dropping the <script> tag.
        // Otherwise, the browser will load the script multiple times,
        // potentially different versions.
        var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
        navigator.serviceWorker.register(serviceWorkerUrl)
          .then((reg) => {
            function waitForActivation(serviceWorker) {
              serviceWorker.addEventListener('statechange', () => {
                if (serviceWorker.state == 'activated') {
                  console.log('Installed new service worker.');
                  loadMainDartJs();
                }
              });
            }
            if (!reg.active && (reg.installing || reg.waiting)) {
              // No active web worker and we have installed or are installing
              // one for the first time. Simply wait for it to activate.
              waitForActivation(reg.installing ?? reg.waiting);
            } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
              // When the app updates the serviceWorkerVersion changes, so we
              // need to ask the service worker to update.
              console.log('New service worker available.');
              reg.update();
              waitForActivation(reg.installing);
            } else {
              // Existing service worker is still good.
              console.log('Loading app from service worker.');
              loadMainDartJs();
            }
          });

        // If service worker doesn't succeed in a reasonable amount of time,
        // fallback to plaint <script> tag.
        setTimeout(() => {
          if (!scriptLoaded) {
            console.warn(
              'Failed to load app from service worker. Falling back to plain <script> tag.',
            );
            loadMainDartJs();
          }
        }, 4000);
      });
    } else {
      // Service workers not supported. Just drop the <script> tag.
      loadMainDartJs();
    }
  </script>

  <!-- The core Firebase JS SDK is always required and must be listed first -->
  <script src="https://www.gstatic.com/firebasejs/8.3.3/firebase-app.js"></script>

  <!-- TODO: Add SDKs for Firebase products that you want to use
       https://firebase.google.com/docs/web/setup#available-libraries -->

  <script>
  // Your web app's Firebase configuration
  var firebaseConfig = {
    apiKey: "AIzaSyCsPqvAN2gvlyCv3J7H1lTscXxB0T5itDE",
    authDomain: "demo159752.firebaseapp.com",
    projectId: "demo159752",
    storageBucket: "demo159752.appspot.com",
    messagingSenderId: "222592650517",
    appId: "1:222592650517:web:ff8984d70b66dfc1fa2d1c"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
</script>

</body>
</html>

我也有同样的问题,我决定等待,15分钟后我的网站出现了。
请重试并稍等片刻。

您的方法是正确的,但请确保您已从正确的文件地址部署。

我曾帮助我解决此问题
{
  "hosting": {
    "public": "build/web",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}