Unable to add Firebase Dynamic Links to a project using a custom domain

I had a similar problem with the root (apex) domain. Basically, if the prefix (the apex domain in my case) is a URL that gives 200 status response, it won't be accepted. In my case the there was an index.html file inside the public folder. I renamed it to something else and it worked.

Here's my firebase.json:

{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "appAssociation": "AUTO",
    "rewrites": [ { "source": "/**", "dynamicLinks": true } ]
  }
}

I had the same issue and got the same error. The problem was that I was redirecting all the routes to index.html. The solution was to restrict the routes to index.html by exclusion.

"rewrites": [
  {
    "source": "/link/**",
    "dynamicLinks": true
  },
  {
    "source": "!/link/**",
    "destination": "/index.html"
  }
]

After deploying the new configuration to Firebase Hosting, I was allowed to use mydomain.example/link as desired.