【问题标题】:Android: lint id AppLinksAutoVerifyWarning always failing but AppLinks work fineAndroid:lint id AppLinksAutoVerifyWarning 总是失败,但 AppLinks 工作正常
【发布时间】:2017-03-07 13:35:39
【问题描述】:

我遇到的问题是 AppLinksAutoVerifyWarning 的 lint 测试总是失败并显示错误消息:

应用链接自动验证失败 ../../src/debug/AndroidManifest.xml:17:此主机不支持指向您的应用的应用链接。检查数字资产链接 JSON 文件: https://myhost/.well-known/assetlinks.json

我正在使用特定于目标的 AndroidManifest 进行调试构建,如您在上面看到的。对于那些调试版本,我将 .debug 后缀附加到我的包名称中。因此调试版本将具有包 ID mypackage.debug,而发布版本将只有 mypackage。两个版本都使用相同的发布密钥签名(由于 sharedUserId),并且我确保assetlinks.json 中的指纹与签名的指纹匹配。对于 myhost,有一个有效的 ssl 证书。

我上传了 assetlinks.json 文件,支持 mypackage.debugmypackage 并确保它具有正确的 应用程序/json mimetype。

  • 在电话上,应用链接工作正常
  • 使用digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://myhost&relation=delegate_permission/common.handle_all_urls 验证不会提供任何错误
  • 使用 adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "http://myhost" 测试 AppLink 工作正常
  • 我使用developers.google.com/digital-asset-links/tools/generator 重新创建、上传和测试了 assetlinks.json,它验证正常并且不会生成具有不同内容的 json 文件
  • 使用 textmate 验证 json 语法
  • 我还尝试将 intent-filter 从调试 AndroidManifest 移动到主清单,将其移动到没有其他 intent- 的其他活动过滤器

所以一切似乎都很好,只是 lint 不起作用。我可以禁用 lint 检查,但我更愿意启用它,这样我就知道何时出现真正的问题。

我观察到的一件事:如果我将应用链接的 intent-filterhttps 更改为 http,则来自 lint 的错误消息会更改to:... has incorrect JSON syntax 这更奇怪,因为 android 本身和谷歌验证服务似乎可以很好地验证它。 (可能与我们将所有流量从 http 转发到 https 有关)

当前的意图过滤器是:

  <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="myhost"
                    android:pathPrefix="/open_app"
                    android:scheme="https"/>


   </intent-filter>

【问题讨论】:

    标签: android lint applinks


    【解决方案1】:

    我刚遇到同样的问题,所以我查看了 lint 检查的源代码:

                switch (result.getValue().mStatus) {
                case STATUS_HTTP_OK:
                    List<String> packageNames = getPackageNameFromJson(
                            result.getValue().mJsonFile);
                    if (!packageNames.contains(packageName)) {
                        context.report(ISSUE_ERROR, host, context.getLocation(host), String.format(
                                "This host does not support app links to your app. Checks the Digital Asset Links JSON file: %s",
                                jsonPath));
                    }
                    break;
    

    这对我来说失败了,因为assetlinks.json 中的包名与我的清单中的包名不匹配。结果我团队中的某个人只完成了将我们的顶级项目转换为库项目的一半,并更改了顶级项目的包名称。但是,如果assetlinks.json 的包名有错别字,也可能发生这种情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-13
      • 2016-10-21
      • 1970-01-01
      • 1970-01-01
      • 2017-09-30
      相关资源
      最近更新 更多