[英]Flutter Web how to serve file assetlinks.json for Android App Links verification
I am deploying a Flutter Web App on Firebase Hosting .我正在Firebase Hosting上部署Flutter Web 应用程序。
And a Flutter App on Android .以及Android 上的 Flutter 应用程序。
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
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?如何在没有 3XX 重定向的情况下从我的域(即部署在 web 上的 Flutter 和 firebase 托管)中提供文件?
If I am not mistaken, Firebase stores files in a so called bucket.如果我没记错的话,Firebase 将文件存储在所谓的存储桶中。 The bucket can be directly exposed to the internet or you can use the API to pull the file you need and put it somewhere public on your domain:
存储桶可以直接暴露在互联网上,或者您可以使用 API 提取您需要的文件并将其放在您的域中的某个公共位置:
https://firebase.google.com/docs/storage/web/list-files https://firebase.google.com/docs/storage/web/list-files
To see how to publish files in a gloud bucket, here is a good answer:要查看如何在 gloud 存储桶中发布文件,这是一个很好的答案:
How do you make many files public in Google Cloud Storage? 如何在 Google Cloud Storage 中公开许多文件?
Be aware the method described provides public access, so make sure you only expose what you want.请注意,所描述的方法提供了公共访问权限,因此请确保您只公开您想要的内容。
It is enough to add the .well-know
folder and the file to the web
folder of your Flutter project.将
.well-know
文件夹和文件添加到 Flutter 项目的web
文件夹中就足够了。
And to change the firebase.json
adding headers and rewrites entries.并更改
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"
}
]
}
}
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感谢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. Firebase 托管会在请求时自动生成
assetlinks.json
和apple-app-site-association
文件。 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).您只需要确保在 项目设置中正确设置了您的应用程序详细信息(包、SHA256 证书指纹等),并确保在
firebase.json
中将属性appAssociation
设置为"AUTO"
(或省略,如AUTO
是默认值)。
Example firebase.json
:示例
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参考: https://firebase.google.com/docs/hosting/full-config#rewrite-dynamic-links
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.