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

Viewed 514

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?

3 Answers

It is enough to add the .well-know 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

Firebase Hosting automatically generates assetlinks.json and apple-app-site-association files when they are requested. It doesn't require any extra configuration.

You just need to make sure that your app details (package, SHA256 certificate fingerprints, etc.) are correctly setup in the Project Settings and make sure that in your firebase.json the property appAssociation is set to "AUTO" (or omitted, as AUTO is the default value).

Example firebase.json:

{
  "hosting": {
    "public": "build/web",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "appAssociation": "AUTO",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

Ref: https://firebase.google.com/docs/hosting/full-config#rewrite-dynamic-links

Related