验证assetlinks.json会给出ERROR_CODE_MALFORMED_CONTENT

时间:2017-11-07 16:22:53

标签: android deep-linking

我正在尝试在我的网络服务器上设置assetlinks.json文件,以指示移动应用应该处理深层链接,并且应该在Android 8上的网站和移动设备之间共享登录凭据。

我在我的开发服务器(https://devtesting.narrpr.com/.well-known/assetlinks.json)上托管了assetlinks.json文件。

[{
        "relation": ["delegate_permission/common.get_login_creds"],
        "target": {
            "namespace": "web",
            "site": "https://devtesting.narrpr.com/"
        }
    },
    {
        "relation": ["delegate_permission/common.get_login_creds", "delegate_permission/common.handle_all_urls"],
            "target": {
                "namespace": "android_app",
                "package_name": "com.rpr.mobile",
                "sha256_cert_fingerprints": [
                    "D3:7B:D8:D7:47:AF:08:2E:BA:EF:02:96:8C:F2:3A:1A:46:F9:B0:81:E9:E3:6D:BA:01:3C:00:59:95:39:8D:21"
                ]
            }
    }
]

当我执行this url进行测试时,会出错:

{
  "maxAge": "599.999999890s",
  "debugString": "********************* ERRORS *********************\n* Error: invalid_argument: Could not parse statement list (not valid JSON): \\357\\273\\277[{\\r\\n\\t\\t\\\"relation\\\": [\\\"delegate_permission/common.get_login_creds\\\"],\\r\\n\\t\\t\\\"target\\\": {\\r\\n\\t\\t\\t\\\"namespace\\\": \\\"web\\\",\\r\\n\\t\\t\\t\\\"site\\\": \\\"https://devtesting.narrpr.com/\\\"\\r\\n\\t\\t}\\r\\n\\t},\\r\\n\\t{\\r\\n\\t\\t\\\"relation\\\": [\\\"delegate_permission/common.get_login_creds\\\", \\\"delegate_permission/common.handle_all_urls\\\"],\\r\\n\\t\\t\\t\\\"target\\\": {\\r\\n\\t\\t\\t\\t\\\"namespace\\\": \\\"droid\\\",\\r\\n\\t\\t\\t\\t\\\"package_name\\\": \\\"com.rpr.mobile\\\",\\r\\n\\t\\t\\t\\t\\\"sha256_cert_fingerprints\\\": [\\r\\n\\t\\t\\t\\t\\t\\\"D3:7B:D8:D7:47:AF:08:2E:BA:EF:02:96:8C:F2:3A:1A:46:F9:B0:81:E9:E3:6D:BA:01:3C:00:59:95:39:8D:21\\\"\\r\\n\\t\\t\\t\\t]\\r\\n\\t\\t\\t}\\r\\n\\t}\\r\\n] [0] while fetching Web statements from https://devtesting.narrpr.com./.well-known/assetlinks.json (which is equivalent to 'https://devtesting.narrpr.com/.well-known/assetlinks.json') using download from the web (ID 1).\n********************* INFO MESSAGES *********************\n* Info: No statements were found that match your query\n",
  "errorCode": [
    "ERROR_CODE_MALFORMED_CONTENT"
  ]
}

在调试行中,它表示它不是有效的json,但是jsonlint要求不同。知道我做错了吗?

3 个答案:

答案 0 :(得分:0)

Android specification requires android_app as namespace.

- "namespace": "droid",
+ "namespace": "android_app",

答案 1 :(得分:0)

通过Android Studio(而不是手动)生成assetlinks.json文件后,它开始工作。不确定我是否遗漏了内容,或者是否是Windows文本编码的问题。

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "android_app",
    "package_name": "com.rpr.mobile",
    "sha256_cert_fingerprints":
    ["D3:7B:D8:D7:47:AF:08:2E:BA:EF:02:96:8C:F2:3A:1A:46:F9:B0:81:E9:E3:6D:BA:01:3C:00:59:95:39:8D:21"]
  }
},
{
  "relation": ["delegate_permission/common.get_login_creds"],
  "target": {
    "namespace": "web",
    "site": "https://devtesting.narrpr.com"
  }
},
{
  "relation": ["delegate_permission/common.get_login_creds"],
  "target": {
    "namespace": "android_app",
    "package_name": "com.rpr.mobile",
    "sha256_cert_fingerprints":
    ["D3:7B:D8:D7:47:AF:08:2E:BA:EF:02:96:8C:F2:3A:1A:46:F9:B0:81:E9:E3:6D:BA:01:3C:00:59:95:39:8D:21"]
  }
}]

答案 2 :(得分:0)

错误来自剪贴板中的文件:

错误:invalid_argument:无法解析语句列表(无效的JSON):\ 357 \ 273 \ 277 [...

删除文件开头的错误字符(\ 357 \ 273 \ 277)或从头开始创建新字符。