android - 在 Android(多个设备)上使用受信任的 Web 活动时出现 NullPointerException
问题描述
我正在使用TrustedWebActivities,我在三星 S8、S9 和 Pixel 2 设备上立即出现应用程序崩溃,并出现以下异常。一些研究表明,这可能发生在安装了不支持 TWA 的旧版 Chrome 并且后备方法失败的设备上。但我已经确认 Chrome 版本是 71(也适用于三星 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 的这一行上,它是一个 type 的对象CustomTabsSession
。这是来源。
session.validateRelationship(CustomTabsService.RELATION_HANDLE_ALL_URLS, uri, null);
任何帮助表示赞赏。谢谢你。
解决方案
您可以更新gradefile中的版本,它应该可以工作
implementation 'com.github.GoogleChrome.custom-tabs-client:customtabs:d08e93fce3fb3e1f22214ee2f23fddc4f4e92634'
正如您可以检查差异一样,验证功能已被删除。
session.validateRelationship(CustomTabsService.RELATION_HANDLE_ALL_URLS, uri, null);
然而,正如谷歌团队在自述文件中提到的那样,我们应该改用 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
推荐阅读
- c# - DataContract 在没有 DataContractAttribute 的情况下工作(直到混淆)
- javascript - Sequelize JS如何处理验证
- reactjs - 如何从 react redux 组件中删除 cookie?
- java - GirdBagLayout 混乱
- javascript - 一种在另一个 html 中使用对象标签显示网页而不使用 jquery 的更好方法,只是普通的 javascript
- php - 获取两个日期之间的出现次数/次数
- node.js - 在 NodeJs 中使用 findOne() 时出现 UnhandledPromiseRejectionWarning
- react-native - 存储来自 api 调用 React native 的结果
- python - 遍历字典中的函数
- ms-access - 在子表单中级联组合框