[App Crash ]CustomTabsSession is required for launching a TWA even session has been created
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
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 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.
Do you know which browser you are connecting to? It will be the packageName parameter you're passing to bindCustomTabsService.
@PEConn
We dont log the browser but our app now only support Chrome package. so it should be chrome.
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 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
@PEConn Any ideas why generate session return different results between androidbrowserhelper and old package custom-tab-client? thanks