flutterflutter-webfirebase-hosting

Flutter Web how to serve file assetlinks.json for Android App Links verification


I am deploying a Flutter Web App on Firebase Hosting.

And a Flutter App on Android.

To use App Links that redirect to my Android application, I need to verify the App Links serving the file assetlinks.json on the web at https://example.com/.well-known/assetlinks.json

How can I make the file available, without 3XX redirects, from my domain, that is Flutter deployed on the web with firebase hosting?


Solution

  • It is enough to add the .well-known folder and the file to the web folder of your Flutter project.

    And to change the firebase.json adding headers and rewrites entries.

    {
      "hosting": {
        "public": "build/web",
        "appAssociation": "NONE",
        "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
        "headers": [
          {
            "source": "/.well-known/assetlinks.json",
            "headers": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ]
          }
        ],
        "rewrites": [
          {
            "source": "/.well-known/assetlinks.json",
            "destination": "/.well-known/assetlinks.json"
          },
          {
            "source": "**",
            "destination": "/index.html"
          }
        ]
      }
    }
    

    build and deploy again and the file is now accessible!

    Thanks for the easy guide to https://blog.bam.tech/developer-news/universal-links-firebase-hosting-and-flutter-web