NullPointerException when using Trusted Web Activities on Android (multiple devices)

自闭症网瘾萝莉.ら 提交于 2019-12-11 12:46:48

问题


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)

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);

Any help is appreciated. Thank you.


回答1:


this issue has been fixed as commit https://github.com/GoogleChrome/custom-tabs-client/commit/51a4ff1d07d8507b934fc9d9af226a969b6c4674?diff=split#diff-39c75633d34184d98d2495b5686172dbL132-R136

you can update the version in gradefile, it should work

implementation '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);

However, as google team mention on readme that we should use Adnroid Browser Helper instead.

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



来源:https://stackoverflow.com/questions/54831881/nullpointerexception-when-using-trusted-web-activities-on-android-multiple-devi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!