在 Android 上使用 Trusted Web Activity 时出现 NullPointerException(多设备) [英] NullPointerException when using Trusted Web Activities on Android (multiple devices)
问题描述
我正在使用 TrustedWebActivities在三星 S8、S9 和 Pixel 2 设备上立即发生应用程序崩溃,并出现以下异常.一些研究表明,这可能发生在安装了不支持 TWA 且回退方法失败的旧版 Chrome 的设备上.但我已经确认 Chrome 版本是 71(而且,这适用于三星 S7、Pixel 3).
I'm using TrustedWebActivities and I'm getting an immediate app crash on Samsung S8, S9, and Pixel 2 devices with the below Exception. Some research suggests that this might happen on devices where there's an older version of Chrome installed which doesn't support TWA and the fall-back method fails. But I've confirmed that the Chrome version is 71 (also, this works on 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
类型的对象.这是 /a>.
I believe this is happening on this line where session
is null, which is an object of type CustomTabsSession
. Here's the source.
session.validateRelationship(CustomTabsService.RELATION_HANDLE_ALL_URLS, uri, null);
感谢任何帮助.谢谢.
推荐答案
this issue has been fixed as commit https://github.com/GoogleChrome/custom-tabs-client/commit/51a4ff1d07d8507b934fc9d9af226a969b6c4674?diff=split#diff-39c75633d34184d98d2495b5686172dbL132-R136
你可以在gradefile中更新版本,它应该可以工作
you can update the version in gradefile, it should work
实现'com.github.GoogleChrome.custom-tabs-client:customtabs:d08e93fce3fb3e1f22214ee2f23fddc4f4e92634'
由于您可以检查差异,因此已删除验证功能.
as you can check the diff, the validate function has been deleted.
session.validateRelationship(CustomTabsService.RELATION_HANDLE_ALL_URLS, uri, null);
但是,正如谷歌团队在自述文件中提到的,我们应该改用 Adnroid 浏览器助手.
However, as google team mention on readme that we should use Adnroid Browser Helper instead.
请改用 Android 浏览器助手库.它包含更新后可与 AndroidX 一起使用的相同功能.
https://github.com/GoogleChrome/android-browser-helper
这篇关于在 Android 上使用 Trusted Web Activity 时出现 NullPointerException(多设备)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!