我正在 Firebase Hosting 上部署 Flutter Web App。
以及 Android 上的 Flutter 应用程序。
要使用重定向到我的 Android 应用程序的应用程序链接,我需要验证在网络上提供文件
assetlinks.json
的应用程序链接,网址为 https://example.com/.well-known/assetlinks.json
如何在没有 3XX 重定向的情况下从我的域(即使用 Firebase 托管部署在 Web 上的 Flutter)提供该文件?
将
.well-know
文件夹和文件添加到 Flutter 项目的 web
文件夹中即可。
并更改
firebase.json
添加标题并重写条目。
{
"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"
}
]
}
}
再次构建并部署,文件现在可以访问!
感谢您的简单指南 https://blog.bam.tech/developer-news/universal-links-firebase-hosting-and-flutter-web
Firebase 托管会在请求时自动生成
assetlinks.json
和 apple-app-site-association
文件。它不需要任何额外的配置。
您只需确保您的应用程序详细信息(包、SHA256 证书指纹等)在 Project Settings 中正确设置,并确保在您的
firebase.json
中,属性 appAssociation
设置为 "AUTO"
(或省略,因为 AUTO
是默认值)。
示例
firebase.json
:
{
"hosting": {
"public": "build/web",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"appAssociation": "AUTO",
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
参考:https://firebase.google.com/docs/hosting/full-config#rewrite-dynamic-links
不要弄乱你熟悉的文件夹的路径。
它应该放置在:build/web 不仅仅是在网络上。
如果我没记错的话,Firebase 将文件存储在所谓的存储桶中。 该存储桶可以直接暴露在互联网上,或者您可以使用 API 来提取您需要的文件并将其放在您域中的公共位置:
https://firebase.google.com/docs/storage/web/list-files
要了解如何在云存储桶中发布文件,这里有一个很好的答案:
如何在 Google Cloud Storage 中公开多个文件?
请注意,所描述的方法提供公共访问,因此请确保仅公开您想要的内容。