TWA - 数字资产 Link 正常,但地址栏仍然可见

TWA - Digital Asset Link OK but address bar still visible

我开发了一个渐进式网络应用程序,我想将其作为可信网络发布在 Play 商店中 Activity。 这是https://www.bagnoadriatico.it

遵循本指南 https://developers.google.com/web/updates/2019/02/using-twa

我从 https://github.com/GoogleChromeLabs/svgomg-twa

我用

更改了配置
def twaManifest = [
    applicationId: 'com.simovinci.bagnoadriatico',
    hostName: 'www.bagnoadriatico.it', // The domain being opened in the TWA.
    launchUrl: '/mobile', // The start path for the TWA. Must be relative to the domain.
    name: 'BagnoAdriatico di Casalborsetti', // The name shown on the Android Launcher.
    themeColor: '#ff5c14', // The color used for the status bar.
    backgroundColor: '#ffff00' // The color used for the splash screen background.
]

然后我签署了 apk,构建并发布到 Play 商店。

在网站上我通过数字资产创建了关联Link https://www.bagnoadriatico.it/.well-known/assetlinks.json "Statement List Generator and Tester"表示操作成功 "Success! Host www.bagnoadriatico.it grants app deep linking to com.simovinci.bagnoadriatico." https://developers.google.com/digital-asset-links/tools/generator

地址栏仍然可见,我不知道为什么。

https://www.bagnoadriatico.it/mobile returns 一个 200 的 http 代码。 PWA 是 100% Lighthouse 验证的。 关键指纹是对的

========================================

我尝试设置 launchUrl = "/"(在我删除 302 到移动版本之前)但没有任何改变。地址栏仍然可见。

assetlinks.json文件实际上是错误的。它包含 Android 标记 网络标记:

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "web",
    "site": "https://www.bagnoadriatico.it"
  }
},{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target" : { "namespace": "android_app", "package_name": "com.simovinci.bagnoadriatico",
               "sha256_cert_fingerprints": ["DA:E2:7C:57:8F:B8:28:ED:C0:00:70:7C:52:1F:95:8E:50:E6:A9:58:50:B0:FB:9A:F1:99:78:C9:D4:6B:72:45"] }
}]

assetlinks.json 包含以下语句就足够了:

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target" : { "namespace": "android_app", "package_name": "com.simovinci.bagnoadriatico",
               "sha256_cert_fingerprints": ["DA:E2:7C:57:8F:B8:28:ED:C0:00:70:7C:52:1F:95:8E:50:E6:A9:58:50:B0:FB:9A:F1:99:78:C9:D4:6B:72:45"] }
}]

我不确定这是否是地址栏可见的根本原因。我还推荐 double-checking:

  • 仔细检查指纹
  • 确保在打开 URL.
  • 时没有重定向到未验证的域

如果有任何帮助,请告诉我。

如果您使用了 Google Play 的应用签名,您的 SHA 256 会发生变化。解决方法是从 Play 商店下载您的应用,然后使用同样来自 Play 商店的以下工具生成新的 assetlinks.json 文件:

https://play.google.com/store/apps/details?id=dev.conn.assetlinkstool&hl=en

我只在模拟器上发现了这个问题。 它在真实设备上完美运行。

问题是模拟器不加载已签名 APK.To 在模拟器上加载已签名的 apk 在 gradle 文件

中添加以下代码
signingConfigs{
        debug{
            keyAlias 'your key alias'
            keyPassword 'your keypassword'
            storeFile file('keystore path')
            storePassword 'your storepassword'
        }
    }
    buildTypes {
        debug{
            signingConfig signingConfigs.debug
        }
 }  

Source

经过多次调试,终于找到地址栏突然又出现的原因:

我们向我们的其他域之一添加了一个 API 调用。这基本上打破了应用程序的“信任”。将 assetlinks.json 也添加到 API 域后,应用程序再次开始隐藏 URL 栏。