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

升级cordova-android@13后自定义URL Scheme与Deep Link功能失效问题求助

升级cordova-android@13后自定义URL Scheme与Deep Link功能失效问题求助

我之前用的是Cordova@11.0.0 + cordova-android@11.1.0,自定义URL Scheme和Deep Link都能正常工作。但升级到Cordova@12.0.0 + cordova-android@13.0.0(对应SDK 34)之后,这两个功能在Android端彻底失效了——不过iOS端用cordova-ios@7.1.1还是正常的。

我的AndroidManifest.xml里的配置是这样的:

<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/activity_name" android:launchMode="singleTask" android:name="MainActivity" android:theme="@style/Theme.App.SplashScreen" android:windowSoftInputMode="adjustPan">
    <intent-filter android:label="@string/launcher_name">
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    <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="myapp"/>
    </intent-filter>
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:host="myappdomain.com" android:scheme="http" android:path="/events"/>
    </intent-filter>
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:host="myappdomain.com" android:scheme="https" android:path="/events"/>
    </intent-filter>
</activity>

补充说明一下:

  • 自定义URL Scheme我用的是cordova-plugin-customurlscheme,这个插件主要负责App打开后的逻辑处理,触发App启动的核心应该还是AndroidManifest里的intent-filter(这部分和插件无关)
  • Deep Link用的是cordova-plugins-deeplinks

我想知道cordova-android@12或@13是不是对自定义URL Scheme的处理逻辑做了改动?

测试情况

  1. Deep Link测试(adb命令)
    执行这条命令:
adb shell am start -W -a android.intent.action.VIEW -d "https://myappdomain.com/events/?r=1008"

结果是直接打开Chrome跳转到网页,而不是启动我的App。我已经在网站部署了.well-known/assetlinks.json,而且旧版本的线上App是正常工作的,所以这个配置应该没问题。

用pm get-app-links查了一下状态,显示:

com.myapp:
  ID: 5a02bf28-5c6b-46b2-b5fe-8e632a2ac505
  Signatures: [00:96:FD:A7:FB:74:98:AF:1D:DC:07:5B:AA:0F:00:94:5E:67:AF:15:9F:4B:82:4D:43:D6:AB:68:38:81:5A:98]
  Domain verification state:
    myappdomain.com: 1024
  User 0:
    Verification link handling allowed: true
    Selection state:
      Enabled:
        myappdomain.com
  1. 自定义URL Scheme测试
    网页端会根据链接尝试用myapp://?r=1008启动App,但完全没反应,浏览器控制台还报了CORS错误:

Access to XMLHttpRequest at 'myapp://r?id=1008' from origin 'https://myappdomian.com' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: chrome, chrome-untrusted, data, http, https, isolated-app.

但直接用adb命令测试URL Scheme是正常的:

adb shell am start -W -a android.intent.action.VIEW -d "myapp://r?id=1234"

App能正常打开,也能跳转到对应内容。这说明URL Scheme本身是有效的,但从网页跳转就不行了。

后续排查

我在论坛看到一个帖子,跟着去手机设置里看了:设置 > 应用 > 默认应用 > 打开链接,我的App的“打开支持的链接”是开启状态,但“支持的网址”里我的域名是禁用的。我手动启用后再测试adb的Deep Link命令,还是不行,依然跳转到网页。

有没有遇到过类似问题的朋友?或者知道cordova-android@13里相关逻辑的改动点的?


内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.08 10:54:54