在Android设备(多个设备)上使用受信任的Web活动时发生NullPointerException

时间:2019-02-22 17:01:10

标签: android google-chrome progressive-web-apps trusted-web-activity

我正在使用TrustedWebActivities,但由于以下异常,在Samsung S8,S9和Pixel 2设备上我立即崩溃。一些研究表明,这可能会在安装了旧版Chrome且不支持TWA且后备方法失败的设备上发生。但我已经确认Chrome版本为71(而且,该版本适用于Samsung S7 Pixel 3)。

java.lang.NullPointerException: 
  at android.support.customtabs.TrustedWebUtils.launchAsTrustedWebActivity (TrustedWebUtils.java:91)
  at android.support.customtabs.trusted.LauncherActivity$TwaCustomTabsServiceConnection.onCustomTabsServiceConnected (LauncherActivity.java:192)
  at android.support.customtabs.CustomTabsServiceConnection.onServiceConnected (CustomTabsServiceConnection.java:44)
  at android.app.LoadedApk$ServiceDispatcher.doConnected (LoadedApk.java:1656)
  at android.app.LoadedApk$ServiceDispatcher$RunConnection.run (LoadedApk.java:1685)
  at android.os.Handler.handleCallback (Handler.java:789)
  at android.os.Handler.dispatchMessage (Handler.java:98)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6938)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)

我相信这是在session为null的这行上发生的,这是CustomTabsSession类型的对象。这是source

  session.validateRelationship(CustomTabsService.RELATION_HANDLE_ALL_URLS, uri, null);

感谢您的帮助。谢谢。

1 个答案:

答案 0 :(得分:0)

此问题已修复为提交 https://github.com/GoogleChrome/custom-tabs-client/commit/51a4ff1d07d8507b934fc9d9af226a969b6c4674?diff=split#diff-39c75633d34184d98d2495b5686172dbL132-R136

您可以在gradefile中更新版本,它应该可以运行

implementation 'com.github.GoogleChrome.custom-tabs-client:customtabs:d08e93fce3fb3e1f22214ee2f23fddc4f4e92634'

您可以检查差异,因此验证功能已删除。

session.validateRelationship(CustomTabsService.RELATION_HANDLE_ALL_URLS, uri, null);

但是,正如Google团队在自述文件中提到的那样,我们应该改用Adnroid Browser Helper。

Please use the Android Browser Helper library instead. It contains the same functionality updated to work with AndroidX. https://github.com/GoogleChrome/android-browser-helper