You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native中HTTP/HTTPS本地主机深度链接失效问题排查

React Native安卓HTTP/HTTPS深度链接无法唤起应用的解决方案

问题核心原因

你的配置存在两个关键错误:

  1. AndroidManifest中host属性包含端口号:安卓的<data>标签里,android:host仅允许填写主机名,端口必须通过android:port单独指定,把localhost:8081直接写在host里会导致系统无法匹配到你的应用。
  2. autoVerify="true"导致验证失败:针对localhost使用autoVerify时,安卓会尝试验证服务器根目录的assetlinks.json文件,但本地服务器未启动或不存在该文件,验证失败后系统会直接将链接交给浏览器处理。

修复步骤

1. 修正AndroidManifest中的Intent Filter

将包含HTTP/HTTPS的intent-filter修改为以下内容,拆分host和port,并移除autoVerify="true":

<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />

  <data android:scheme="http" android:host="localhost" android:port="8081" />
  <data android:scheme="https" android:host="localhost" android:port="8081" />
</intent-filter>

2. 完善React Navigation Linking配置

确保prefixes包含HTTPS的地址,避免遗漏:

const linking = {
  prefixes: ["area://", "http://localhost:8081", "https://localhost:8081"],
  config: {
    screens: {
      Login: 'Login',
      Register: 'Register',
      Auth: 'Auth',
      ForgotPassword: 'ForgotPassword',
      ResetPassword: 'ResetPassword',
      Homepage: '',
      Create: 'Create',
      Activity: 'Activity',
      User: 'Areas'
    }
  }
};

export default linking;

3. 重新构建并安装应用

修改AndroidManifest后必须重新打包安装,执行以下命令:

npx react-native run-android

4. 准确测试深度链接

使用adb命令直接指定应用测试,避免浏览器缓存干扰:

adb shell am start -a android.intent.action.VIEW -d "http://localhost:8081" com.area

内容的提问来源于stack exchange,提问作者Diamonddedo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 04:40:25