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

点击Deep Link无法打开Flutter应用,跳转至404页面问题求助

问题描述

在Yahoo邮箱中收到一条验证链接,点击该链接本应跳转至我的Flutter应用,但实际打开了404页面;不过使用adb测试命令可以正常打开应用。我当前使用App Links实现深度链接,相关代码及Android Manifest配置如下:

Flutter 代码实现

1. MyApp 状态类

class _MyAppState extends State<MyApp> {
  var loading=true.obs;
  final _appLinks = AppLinks();
  final profileController=Get.put(ProfileController());

  @override
  void initState() {
    profileController.initData();
    Timer(const Duration(seconds: 5), () {
      loading.value=false;
    });
    _appLinks.allUriLinkStream.listen((uri) {
      String? userId = uri.queryParameters['userid'];
      String? token = uri.queryParameters['token'];
      if(kDebugMode){
        print('User ID: $userId');
        print('Token: $token');
      }
      Get.offNamed("/verify_client",arguments: [userId,token]);
    });
    super.initState();
  }
}
void main() async{
  WidgetsFlutterBinding.ensureInitialized();
  await VerificationHandler.initUniLinks();
  runApp(const MyApp());
}
class VerificationHandler {
  static late StreamSubscription sub;
  static  initUniLinks() async {
    final initialLink = await getInitialLink();

    sub = uriLinkStream.listen((Uri? uri) {
     if(uri!=null){
       if(kDebugMode){
         print(initialLink);
         print(uri);
       }
       if (uri.host == 'mohamyninja.com' ||uri.host=='new.mohamyninja.com'){
         String? userId = uri.queryParameters['userid'];
         String? token = uri.queryParameters['token'];
         if(kDebugMode){
           print('User ID: $userId');
           print('Token: $token');
         }
         Get.offNamed("/verify_client",arguments: [userId,token]);
       }
     }
      // Use the uri and warn the user, if it is not correct
    }, onError: (err) {
      // Handle exception by warning the user their action did not succeed
    });
  }
}

Android Manifest 配置

<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="https" android:host="mohamyninja.com" android:pathPrefix="/" />
    <data android:scheme="https" android:host="new.mohamyninja.com" android:pathPrefix="/" />
            <data android:scheme="http" />
</intent-filter>

验证链接示例

https://mohamyninja.com/userid=51_token=dcfde478bd46d67b5a4e1aada7b27188


排查与解决方案
  1. 修正链接格式
    你提供的验证链接参数格式错误,正确格式需用?开头、&分隔参数:https://mohamyninja.com/?userid=51&token=dcfde478bd46d67b5a4e1aada7b27188。原格式中浏览器会把userid=51_token=...当作路径,服务器找不到对应资源返回404,无法触发App Links跳转。

  2. 校验App Links验证状态

    • 检查域名下是否存在/.well-known/assetlinks.json文件,路径需为https://mohamyninja.com/.well-known/assetlinks.json和https://new.mohamyninja.com/.well-known/assetlinks.json,文件内容要正确关联应用签名与包名。Yahoo邮箱会严格校验App Links验证状态,未通过则直接用浏览器打开链接。
    • 确认android:autoVerify="true"已添加,若assetlinks.json配置错误,系统会忽略App Links规则。
  3. 优化Intent Filter配置
    单独的<data android:scheme="http" />会匹配所有http链接,易引发冲突,应将scheme与host绑定:

    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="https" android:host="mohamyninja.com" />
        <data android:scheme="https" android:host="new.mohamyninja.com" />
        <data android:scheme="http" android:host="mohamyninja.com" />
        <data android:scheme="http" android:host="new.mohamyninja.com" />
    </intent-filter>
    

    无需设置pathPrefix="/",默认匹配所有路径。

  4. 移除冗余代码
    同时使用app_links和uni_links两个库会导致监听冲突,建议只保留一个库处理深度链接。

  5. 验证测试

    • 修正链接格式后,先在浏览器中打开测试跳转;若仍失败,用adb shell am start -a android.intent.action.VIEW -d "修正后的链接" 你的应用包名确认链接可被正确识别。
    • 直接访问assetlinks.json地址,确认文件可访问且格式正确。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 04:35:54