1

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.

Nightwolf
  • 4,495
  • 2
  • 21
  • 29
  • Which version of the Support Library are you using? Are you using the LauncherActivity provided with the Support Library (https://github.com/GoogleChrome/custom-tabs-client/blob/master/customtabs/src/android/support/customtabs/trusted/LauncherActivity.java) – andreban Feb 25 '19 at 16:41

1 Answers1

0

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

Vo Thanh Tung
  • 370
  • 1
  • 6
  • 20