android-browser-helper: Crash on start: Non-browser selected

Describe the bug While the default system browser (where any link opens by default) is set to an actual browser (Brave, also tried setting to Chrome), for some reason an app that is not a browser and does not appear in the system browser selection (Revolut) is selected as TWA provider which causes a crash on start.

To Reproduce Launching the app on my phone in debug mode returns these logs before the app crashes:

D/TWALauncherActivity: Using URL from Manifest (https://travelfeed.io/?utm_source=pwa).
D/TWAProviderPicker: Found browser: com.revolut.revolut
    Found browser: com.revolut.revolut
D/TWAProviderPicker: Found no TWA providers, using first browser: com.revolut.revolut
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: io.travelfeed.twa, PID: 14612
    java.lang.RuntimeException: Unable to start activity ComponentInfo{io.travelfeed.twa/com.google.androidbrowserhelper.trusted.LauncherActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://travelfeed.io/... pkg=com.revolut.revolut (has extras) }
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3114)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7050)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
     Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://travelfeed.io/... pkg=com.revolut.revolut (has extras) }
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2018)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
        at android.app.Activity.startActivityForResult(Activity.java:4689)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767)
        at android.app.Activity.startActivityForResult(Activity.java:4647)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:754)
        at android.app.Activity.startActivity(Activity.java:5008)
        at androidx.core.content.ContextCompat.startActivity(ContextCompat.java:251)
        at androidx.browser.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:331)
        at com.google.androidbrowserhelper.trusted.TwaLauncher.lambda$static$0(TwaLauncher.java:51)
        at com.google.androidbrowserhelper.trusted.-$$Lambda$TwaLauncher$yiLzsm37NbSon1-dZ2dCvDJv8wU.launch(Unknown Source:0)
        at com.google.androidbrowserhelper.trusted.TwaLauncher.launch(TwaLauncher.java:166)
        at com.google.androidbrowserhelper.trusted.LauncherActivity.onCreate(LauncherActivity.java:158)
        at android.app.Activity.performCreate(Activity.java:7327)
        at android.app.Activity.performCreate(Activity.java:7318)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3094)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7050) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965) 

Expected behavior The app should not crash

Smartphone (please complete the following information):

  • Device: SM-G950F
  • OS: Android 9 on newest patch (April 1 2020)
  • Browser: Brave Browser

Originally posted at https://github.com/GoogleChromeLabs/bubblewrap/issues/143 @tiotdev FYI

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 25 (13 by maintainers)

Most upvoted comments

I have prepared a package (1.3.1-alpha01) today. The plan is to make it available to use tomorrow via the Google Maven. I’ll update the the issue once available. When we have some apps using it and we can confirm the issue is indeed fixed, we’ll release 1.3.1.

Also started to get this same error on the 16th April, and it is still ongoing:

image

This error seems similar to one when we first created our TWA, but google released an updated custom tabs version to rectify the error. So to be explicit, our implementation is set to:

implementation 'com.github.GoogleChrome:custom-tabs-client:809a55cfa2'

@dazbradbury a bit unrelated to this issue, but the recommended way of using Trusted Web Activity is via android-browser-helper currently: https://developers.google.com/web/android/trusted-web-activity/android-browser-helper-migration

Can confirm after the update I stopped seeing this error.

#104 should fix this

I’m afraid it doesn’t seem the google play console provides that information (unless I’m missing something?). There is a second similar exception though that is logged as a second “crash cluster”:

image

But I’m not sure if that’s helpful at all, and think this is simply due to a different Android version.

For this particular error, unlikely - But there are other issues fixed in the new library, and many other features.

This comment https://github.com/GoogleChrome/android-browser-helper/issues/89#issuecomment-619984167 describes what I could understand from the issue - It’s about PackageManager returning an app that doesn’t actually handle the URL we’re trying to launch. So, when we actually try to launch we get an ActvityNotFoundException. The logic for picking the provider is here.

In the case of TrustedWebActivity, we know the URL that’s going to be launched beforehand. I’m wondering if it’s worth running the PackageManager against startUrl - This may return the app itself as a handler, but we know the package and can ignore it.

@PEConn, thoughts?