android-browser-helper icon indicating copy to clipboard operation
android-browser-helper copied to clipboard

[App Crash ]CustomTabsSession is required for launching a TWA even session has been created

Open thanhtungka91 opened this issue 4 years ago • 7 comments

Describe the bug App crash in some model when start TWA activity

To Reproduce Steps to reproduce the behavior: Open the App and crash (get log from Firebase)

Expected behavior No crash app

Did this ever used to work In the previous version https://github.com/GoogleChrome/custom-tabs-client it works fine

Code Snippets Fatal Exception: java.lang.NullPointerException: CustomTabsSession is required for launching a TWA at java.util.Objects.requireNonNull(Objects.java:245) at androidx.browser.trusted.TrustedWebActivityIntentBuilder.build(TrustedWebActivityIntentBuilder.java:284) at jp.co.rakuten.pasha.activity.MainActivity$TwaCustomTabsServiceConnection.onCustomTabsServiceConnected(MainActivity.java:185) at androidx.browser.customtabs.CustomTabsServiceConnection.onServiceConnected(CustomTabsServiceConnection.java:57) at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2002) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2034) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:8240) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:979) Smartphone (please complete the following information):

  • Device: AQUOS sense4 basic A003SH
  • OS:11
  • Browsers Installed: chrome
  • Browser Versions latest version
  • android-browser-helper library version: latest

Our code https://gist.github.com/thanhtungka91/56e9e26f7254a4ba62fb8078e1afb73e

Additional context Happen in only some devices AQUOS sense4 basic A003SH, F-04K

thanhtungka91 avatar Sep 21 '21 02:09 thanhtungka91

This message is created when passing null to TrustedWebActivityIntentBuilder#build().

Your code is checking if mSession is null, shows a Toast, but still calls build, which causes the Exception. It the application is unable to create a session.

andreban avatar Sep 21 '21 09:09 andreban

@andreban an

Could you explain why mSession is null? what is root case lead to session to null? Because it didn't happen on the chrome custom tab https://github.com/GoogleChrome/custom-tabs-client even we also create a session.

thanhtungka91 avatar Sep 22 '21 01:09 thanhtungka91

Do you know which browser you are connecting to? It will be the packageName parameter you're passing to bindCustomTabsService.

PEConn avatar Sep 24 '21 06:09 PEConn

@PEConn
We dont log the browser but our app now only support Chrome package. so it should be chrome.

thanhtungka91 avatar Sep 27 '21 04:09 thanhtungka91

Oh, it looks like the issue is that you're passing CustomTabsCallback as null (on line 2 here).

If you pass in a non-null CustomTabsCallback it should work.

PEConn avatar Sep 28 '21 12:09 PEConn

@PEConn Thank you for the reply. I am following the package's demo. https://github.com/GoogleChrome/android-browser-helper/blob/1f9d8febb6fad15b185a79aa890f9e8ee6935d74/demos/twa-custom-launcher/src/main/java/com/google/androidbrowserhelper/launchtwa/LaunchTwaActivity.java#L61-L71

As you see, in the code the CustomTabsCallback in line 61 is also null. mSession = client.newSession(null, SESSION_ID);

How to pass a non-null CustomTabsCallback?
Thanks

thanhtungka91 avatar Sep 29 '21 00:09 thanhtungka91

@PEConn Any ideas why generate session return different results between androidbrowserhelper and old package custom-tab-client? thanks

thanhtungka91 avatar Oct 05 '21 01:10 thanhtungka91