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

无法修改自动生成的Config.xml,能否通过Plugin.xml添加Universal Links配置?

Got it, let's tackle this problem. Since you can't modify config.xml directly, we can hardcode the Universal Links configuration into the cordova-universal-links-plugin source code instead. Here's how to do it step by step:

1. Locate the Plugin Directory

First, find the installed plugin folder in your Cordova project. It should be at this path:

plugins/cordova-universal-links-plugin/

2. Modify the Configuration Parser

The plugin reads Universal Links settings from config.xml using a dedicated parser file. We'll override this logic to return our desired configuration directly.

Navigate to lib/configParser.js inside the plugin directory. Open this file, and replace the existing parse function with our hardcoded configuration.

Original (simplified) code:

module.exports.parse = function(xmlContent) {
    // Existing logic to parse <universal-links> from config.xml
    // ...
    return config;
};

Modified code:

module.exports.parse = function(xmlContent) {
    // Hardcode our Universal Links configuration
    return {
        hosts: [
            {
                name: "example.com",
                paths: [
                    { url: "/some/path" }
                ]
            }
        ]
    };
};

This forces the plugin to use your specified host and path regardless of what's in config.xml.

3. Regenerate Platform Configurations

Run the Cordova prepare command for your target platforms to let the plugin generate the required native configuration files:

# For iOS
cordova prepare ios

# For Android
cordova prepare android
  • On iOS, this will update the Entitlements-*.plist file with the com.apple.developer.associated-domains entitlement (applinks:example.com) and handle path associations.
  • On Android, this will create/update the assetlinks.json file in android/app/src/main/assets/.well-known/ with the correct domain and app ID mappings (if the plugin supports it).

4. Key Notes

  • Plugin Updates: If you ever update the cordova-universal-links-plugin in the future, your changes will be overwritten. To avoid this, consider forking the plugin repository, applying your changes there, and installing the plugin from your fork instead of the official repo.
  • Domain Setup: Don't forget to configure the apple-app-site-association (iOS) and assetlinks.json (Android) files on your example.com domain—these are required for Universal Links to work properly.
  • Testing: Always rebuild your entire project after making these changes to ensure the native configurations are applied correctly.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:33:07