Android applinks 在已发布的版本中不起作用,但在本地安装中可以正常工作

Android applinks not working in released build but work correctly from a local install

我有一个 game 正在使用应用程序link。当 运行 从我的计算机调试和发布版本时,应用程序 link 工作正常,但不适用于从 Google Play 下载的版本。使用 Google Play 版本时,我会收到一个对话框,询问哪个应用程序应该打开 link。

我使用“Google Play 的应用程序签名”并了解发布的 APK 由 Google 签名并且具有不同的签名。我已将 Google Play 上列出的应用签名证书中的 SHA-256 证书指纹添加到我的 assetlinks.json 中,因此它包含来自本地和 Google Play 版本的指纹。

我还从 Google Play 下载了一个派生 APK,并确保指纹与 assetlinks.json 文件中的相匹配。

这是一个示例 URL,当在 Android 中单击时应该会打开应用程序,它在本地构建中会打开应用程序,但在 Google Play 版本中不会。相反,我收到一个对话框,询问哪个应用程序应该打开 link.

https://letsdraw.fun/ec?parent=Z0ibN7m-H8jO1jCiMRQtY23VTpKjnIch

我正在从实时发布版本的 logcat 中写出 SHA256 指纹,以仔细检查它是否正确,一切看起来都很好。

原始签名 APK 和 Google Play 签名 APK 可以从 here 下载。这两个 APK 都是从 Google Play 下载的,一个是“原始的”,一个是“派生的”,所以除了签名之外它们应该是相同的。有趣的是,它们的尺寸略有不同。 11,590,297 字节与 11,601,619 字节。

查看 adb shell dumpsys package domain-preferred-apps 的输出,原始签名的 apk 是

  Package: com.scribble.exquisitecorpse
  Domains: letsdraw.fun scribble-cloud.appspot.com scribble-cloud-v24-test-dot-scribble-cloud.appspot.com
  Status:  always : 200000000

而 Google Play 签名 apk 是

  Package: com.scribble.exquisitecorpse
  Domains: letsdraw.fun scribble-cloud.appspot.com scribble-cloud-v24-test-dot-scribble-cloud.appspot.com
  Status:  ask

用@ymindstorm提到的测试页测试时

https://developers.google.com/digital-asset-links/tools/generator

我收到消息

Success! Host letsdraw.fun grants app deep linking to com.scribble.exquisitecorpse.

对于可能导致此问题的原因,您有什么建议吗?

更新: 我现在已将此作为错误报告给 Google,因为我无法弄清楚发生了什么。 https://issuetracker.google.com/issues/162564916

documentation 状态:

To enable link handling verification for your app, set android:autoVerify="true" in any one of the web URL intent filters in your app manifest that include the android.intent.action.VIEW intent action and android.intent.category.BROWSABLE intent category [...]

When android:autoVerify="true" is present on any one of your intent filters, installing your app on devices with Android 6.0 and higher causes the system to attempt to verify all hosts associated with the URLs in any of your app's intent filters. Verification involves the following:

The system inspects all intent filters that include:

  • Action: android.intent.action.VIEW
  • Categories: android.intent.category.BROWSABLE and android.intent.category.DEFAULT
  • Data scheme: http or https For each unique host name found in the above intent filters, Android queries the corresponding websites for the Digital Asset Links file at https://<hostname>/.well-known/assetlinks.json.

Only if the system finds a matching Digital Asset Links file for all hosts in the manifest does it then establish your app as the default handler for the specified URL patterns.

因此,为了让您跳过消歧对话框,您需要确认您的应用配置正确并且 assetlinks.json 在正确的位置可用。 根据经验,常见的陷阱是:

  • 忘记了 autoVerify
  • 在一个语句中声明了多个 link 并且没有在每个域上都存在正确的关联文件
  • 忘记之前授予开发应用特殊权限
  • 安装了多个试图将自己注册为 link
  • 的解析器的应用程序

您可以使用这个方便的工具来检查您的配置文件是否正确:

https://developers.google.com/digital-asset-links/tools/generator

我最终得到了 Google 的帮助...这不是错误。

构建过程正在从 network_security_config.xml 文件合并到主机中,因此即使指定了 AndroidManifest.xml 文件:

        <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="letsdraw.fun" android:pathPrefix="/ec" android:scheme="https" />
            <data android:host="letsdraw.fun" android:pathPrefix="/restore" android:scheme="https" />
        </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:scheme="http"
                android:host="scribble-cloud-v24-test-dot-scribble-cloud.appspot.com"
                android:pathPrefix="/ec" />

            <data
                android:scheme="https"
                android:host="scribble-cloud.appspot.com"
                android:pathPrefix="/ec" />

            <data
                android:scheme="https"
                android:host="letsdraw.fun"
                android:pathPrefix="/ec" />

            <data
                android:scheme="https"
                android:host="letsdraw.fun"
                android:pathPrefix="/restore" />
        </intent-filter>

this 页面上指出

Only if the system finds a matching Digital Asset Links file for all hosts in the manifest does it then establish your app as the default handler for the specified URL patterns.

问题是我的测试主机没有返回与其他主机相同的 assetlinks.json 文件。

构建 APK 后,使用 IntelliJ 或 Android Studio 转到 Build | Analyze Apk 并打开刚刚构建的 APK 以检查您的主机是否正确并且 assetlinks.json 文件返回正确的签名。

为什么要这样合并清单文件?希望我们能找到 here!