安卓应用链接
了解如何配置 Android 应用链接以从标准 Web URL 打开你的 Expo 应用。
要为你的应用配置 Android 应用链接,你需要:
🌐 To configure Android App Links for your app, you need to:
- 在项目的应用配置中添加
intentFilters并将autoVerify设置为 true - 设置双向关联以验证你的网站和原生应用

将 intentFilters 添加到应用配置中
🌐 Add intentFilters to the app config
通过添加 android.intentFilters 属性并将 autoVerify 设置为 true 来配置你的应用配置。指定 autoVerify 对于 Android 应用链接的正常工作是必需的。
🌐 Configure your app config by adding the android.intentFilters property and setting the autoVerify attribute to true. Specifying autoVerify is required for Android App Links to work correctly.
以下示例显示了一个基本配置,使你的应用可以作为处理指向 webapp.io 域的任何链接的选项出现在标准 Android 对话框中。它还使用常规的 https 方案,因为 Android 应用链接 与 标准深层链接 不同。
🌐 The following example shows a basic configuration that enables your app to appear in the standard Android dialog as an option for handling any links to the webapp.io domain. It also uses the regular https scheme since Android App Links are different from standard deep links.
{ "expo": { "android": { "intentFilters": [ { "action": "VIEW", "autoVerify": true, "data": [ { "scheme": "https", "host": "*.webapp.io", "pathPrefix": "/records" } ], "category": ["BROWSABLE", "DEFAULT"] } ] } } }
在应用/扩展之间共享数据库(iOS)
🌐 Set up two-way association
要在网站和 Android 应用之间设置双向关联,你需要以下内容:
🌐 To setup two-way association between the website and Android app, you will need the following:
- 网站验证: 这需要在目标网站的 /.well-known 目录下创建一个 assetlinks.json 文件并进行托管。此文件用于验证从给定链接打开的应用是否为正确的应用。
- 本地应用验证: 这需要某种形式的代码签名,并引用目标网站域名(URL)。
创建 assetlinks.json 文件
🌐 Create assetlinks.json file
1
为网站验证创建一个 assetlinks.json 文件(也称为 数字资源链接 文件),路径为 /.well-known/assetlinks.json。此文件用于验证应用是否为特定链接打开。
🌐 Create an assetlinks.json file for the website verification (also known as digital asset links file) at /.well-known/assetlinks.json. This file is used to verify that the app opened for a given link.
如果你使用 Expo Router 来构建你的网站(或其他现代 React 框架,如 Remix、Next.js 等),请在 public/.well-known/assetlinks.json 创建 assetlinks.json。对于旧的 Expo webpack 项目,请在 web/.well-known/assetlinks.json 创建该文件。
🌐 If you're using Expo Router to build your website (or any other modern React framework such as Remix, Next.js, and so on), create assetlinks.json at public/.well-known/assetlinks.json. For legacy Expo webpack projects, create the file at web/.well-known/assetlinks.json.
2
从你的应用配置中获取 package_name 的值,位于 android.package 下。
🌐 Get the value of package_name from your app config, under android.package.
3
从你的应用签名证书中获取 sha256_cert_fingerprints 的值。如果你使用 EAS Build 来构建你的 Android 应用,在创建构建之后:
🌐 Get the value of sha256_cert_fingerprints from your app's signing certificate. If you're using EAS Build to build your Android app, after creating a build:
- 运行
eas credentials -p android命令,并选择构建配置文件以获取其指纹值。 - 复制列在
SHA256 Fingerprint下的指纹值。
从 Google Play 控制台获取 SHA256 证书指纹的替代方法
如果你没有使用 EAS 来管理代码签名,你可以通过手动构建并提交你的应用到 Google Play 控制台 来找到 sha256_cert_fingerprints:
🌐 If you're not using EAS to manage code signing, you can find the sha256_cert_fingerprints by building and submitting your app manually to the Google Play Console:
- 在 Google Play 控制台的仪表板中,进入 发布 > 设置 > 应用签名。
- 为你的应用找到正确的 数字资源链接 JSON 片段。
- 复制类似
14:6D:E9:83...的值,并将其粘贴到你的 public/.well-known/assetlinks.json 文件中sha256_cert_fingerprints下。
4
将 package_name 和 sha256_cert_fingerprints 添加到 assetlinks.json 文件中:
🌐 Add package_name and sha256_cert_fingerprints to the assetlinks.json file:
[ { "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "com.example", "sha256_cert_fingerprints": [ // Supports multiple fingerprints for different apps and keys "14:6D:E9:83:51:7F:66:01:84:93:4F:2F:5E:E0:8F:3A:D6:F4:CA:41:1A:CF:45:BF:8D:10:76:76:CD" ] } } ]
信息 你可以向
sha256_cert_fingerprints数组中添加多个指纹,以支持你的应用的不同版本。更多信息,请参见 Android 关于如何声明网站关联的文档。
托管 assetlinks.json 文件
🌐 Host assetlinks.json file
使用你的域名通过网络服务器托管 assetlinks.json 文件。该文件必须以内容类型 application/json 提供,并且可以通过 HTTPS 连接访问。通过在地址栏中输入完整的 URL,验证你的浏览器是否可以访问此文件。
🌐 Host the assetlinks.json file using a web server with your domain. This file must be served with the content-type application/json and accessible over an HTTPS connection. Verify that your browser can access this file by typing the complete URL in the address bar.
原生应用验证
🌐 Native app verification
在 Android 设备上安装该应用以触发Android 应用验证流程。
🌐 Install the app on an Android device to trigger the Android app verification process.
打开应用后,请参阅 在应用中处理链接 了解更多关于如何处理传入链接并向用户显示其请求内容的信息。
🌐 Once you have your app opened, see Handle links into your app for more information on how to handle inbound links and show the user the content they requested.
调试
🌐 Debugging
Expo CLI 使你可以在不部署网站的情况下测试 Android 应用链接。利用 --tunnel 功能,你可以将开发服务器转发到公开可用的 HTTPS URL。
🌐 The Expo CLI enables you to test Android App Links without deploying a website. Utilizing the --tunnel functionality, you can forward your dev server to a publicly available HTTPS URL.
1
设置环境变量 EXPO_TUNNEL_SUBDOMAIN=my-custom-domain,其中 my-custom-domain 是你在开发过程中使用的唯一字符串。这可以确保你的隧道 URL 在开发服务器重启时保持一致。
🌐 Set the environment variable EXPO_TUNNEL_SUBDOMAIN=my-custom-domain where my-custom-domain is a unique string that you use during development. This ensures that your tunnel URL is consistent across dev server restarts.
2
按照上文所述 described above 将 intentFilters 添加到你的应用配置中。将 host 值替换为 Ngrok URL:my-custom-domain.ngrok.io。
🌐 Add intentFilters to your app config as described above. Replace the host value with a Ngrok URL: my-custom-domain.ngrok.io.
3
使用 --tunnel 标志启动你的开发服务器:
🌐 Start your dev server with the --tunnel flag:
- npx expo start --tunnel4
在你的设备上编译开发版:
🌐 Compile the development build on your device:
- npx expo run:android5
使用以下 adb 命令启动意图活动并在你的应用中打开链接,或在设备的网页浏览器中输入自定义域名链接。
🌐 Use the following adb command to start the intent activity and open the link on your app or type the custom domain link in your device's web browser.
- adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "https://my-custom-domain.ngrok.io/" <your-package-name>故障排除
🌐 Troubleshooting
以下是一些在实现 Android 应用链接时帮助你排除故障的常见提示:
🌐 Here are some common tips to help you troubleshoot when implementing Android App Links:
- 确保你的网站通过 HTTPS 提供服务,并使用内容类型
application/json - 验证 Android 应用链接
- Android 验证可能需要 20 秒或更长时间才能生效,因此请务必等到验证完成。
- 如果你更新了 Web 文件,请重建原生应用以在供应商端(Google)触发服务器更新