pichillilorenzo / flutter_inappwebview

A Flutter plugin that allows you to add an inline webview, to use a headless webview, and to open an in-app browser window.
https://inappwebview.dev
Apache License 2.0
3.14k stars 1.46k forks source link

[ANDROID] ChromeSafariBrowser: Setting package name crashes the app if browser is not found #2055

Open luckyhandler opened 6 months ago

luckyhandler commented 6 months ago

Environment

Android 14
Plugin version 6.0.0
Chrome version 122.0.6261.105
flutter doctor                                                                                                                     ~/Downloads 1 ↵ 
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.1, on macOS 14.3.1 23D60 darwin-arm64, locale de-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] IntelliJ IDEA Community Edition (version 2023.2.5)
[✓] VS Code (version 1.87.0)
• No issues found!

Device information: Google Pixel 7a

Description

The plugin crashes the app if a package cannot be found. It is not possible to catch the error to display an error message to the user.

Expected behavior: If a browser with a certain package name is not found the plugin crashes but in a way that it can be caught.

Current behavior: If a browser with a certain package name is not found the plugin crashes but the error cannot be caught.

Steps to reproduce

  1. Deactivate chrome inside your Android system
  2. Run this piece of code
  3. It neither goes into the catch block nor into the onError statement.
    
    try {
    await browser.open(
         url: WebUri.uri(Uri.parse('https://www.uryde.de/en')),
         settings: ChromeSafariBrowserSettings(
             enableUrlBarHiding: true,
             isSingleInstance: true,
             navigationBarColor: theme.primaryColor,
             packageName: Platform.isAndroid ? 'com.android.chrome' : null,
          ),
    ).onError((error, stackTrace) {
        // Show error
    });
    } catch (e) {
    // Show error
    }
It crashes with the following log:

D/CustomTabsActivity(29164): Custom Tabs Engagement Signals API not supported D/CustomTabsActivity(29164): java.lang.NoSuchMethodError: No virtual method isEngagementSignalsApiAvailable(Landroid/os/Bundle;)Z in class Landroidx/browser/customtabs/CustomTabsSession; or its super classes (declaration of 'androidx.browser.customtabs.CustomTabsSession' appears in /data/app/~~bzB2IhB71GvIIiiYES3yOA==/-Fgo7ftD6mv5WBEw5V_CjhQ==/base.apk) D/CustomTabsActivity(29164): at com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.ChromeCustomTabsActivity.customTabsConnected(ChromeCustomTabsActivity.java:224) D/CustomTabsActivity(29164): at com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.ChromeCustomTabsActivity$1.onCustomTabsConnected(ChromeCustomTabsActivity.java:117) D/CustomTabsActivity(29164): at com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.CustomTabActivityHelper.onServiceConnected(CustomTabActivityHelper.java:152) D/CustomTabsActivity(29164): at com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.ServiceConnection.onCustomTabsServiceConnected(ServiceConnection.java:24) D/CustomTabsActivity(29164): at androidx.browser.customtabs.CustomTabsServiceConnection.onServiceConnected(CustomTabsServiceConnection.java:57) D/CustomTabsActivity(29164): at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2313) D/CustomTabsActivity(29164): at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2350) D/CustomTabsActivity(29164): at android.os.Handler.handleCallback(Handler.java:958) D/CustomTabsActivity(29164): at android.os.Handler.dispatchMessage(Handler.java:99) D/CustomTabsActivity(29164): at android.os.Looper.loopOnce(Looper.java:230) D/CustomTabsActivity(29164): at android.os.Looper.loop(Looper.java:319) D/CustomTabsActivity(29164): at android.app.ActivityThread.main(ActivityThread.java:8893) D/CustomTabsActivity(29164): at java.lang.reflect.Method.invoke(Native Method) D/CustomTabsActivity(29164): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608) D/CustomTabsActivity(29164): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103) D/AndroidRuntime(29164): Shutting down VM E/AndroidRuntime(29164): FATAL EXCEPTION: main E/AndroidRuntime(29164): Process: PID: 29164 E/AndroidRuntime(29164): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=... pkg=com.android.chrome (has extras) } E/AndroidRuntime(29164): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2252) E/AndroidRuntime(29164): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1878) E/AndroidRuntime(29164): at android.app.Activity.startActivityForResult(Activity.java:5743) E/AndroidRuntime(29164): at android.app.Activity.startActivityForResult(Activity.java:5701) E/AndroidRuntime(29164): at com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.CustomTabActivityHelper.openCustomTab(CustomTabActivityHelper.java:54) E/AndroidRuntime(29164): at com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.CustomTabActivityHelper.openCustomTab(CustomTabActivityHelper.java:63) E/AndroidRuntime(29164): at com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.ChromeCustomTabsActivity.launchUrlWithSession(ChromeCustomTabsActivity.java:200) E/AndroidRuntime(29164): at com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.ChromeCustomTabsActivity.launchUrl(ChromeCustomTabsActivity.java:185) E/AndroidRuntime(29164): at com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.ChromeCustomTabsActivity.customTabsConnected(ChromeCustomTabsActivity.java:255) E/AndroidRuntime(29164): at com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.ChromeCustomTabsActivity$1.onCustomTabsConnected(ChromeCustomTabsActivity.java:117) E/AndroidRuntime(29164): at com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.CustomTabActivityHelper.onServiceConnected(CustomTabActivityHelper.java:152) E/AndroidRuntime(29164): at com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.ServiceConnection.onCustomTabsServiceConnected(ServiceConnection.java:24) E/AndroidRuntime(29164): at androidx.browser.customtabs.CustomTabsServiceConnection.onServiceConnected(CustomTabsServiceConnection.java:57) E/AndroidRuntime(29164): at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2313) E/AndroidRuntime(29164): at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2350) E/AndroidRuntime(29164): at android.os.Handler.handleCallback(Handler.java:958) E/AndroidRuntime(29164): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(29164): at android.os.Looper.loopOnce(Looper.java:230) E/AndroidRuntime(29164): at android.os.Looper.loop(Looper.java:319) E/AndroidRuntime(29164): at android.app.ActivityThread.main(ActivityThread.java:8893) E/AndroidRuntime(29164): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(29164): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608) E/AndroidRuntime(29164): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

So it would be enough to catch the error and [react accordingly](https://developer.android.com/training/basics/intents/sending):

```kotlin
try {
    startActivity(intent)
} catch (e: ActivityNotFoundException) {
    // Define what your app should do if no activity can handle the intent.
}
github-actions[bot] commented 6 months ago

👋 @luckyhandler

NOTE: This comment is auto-generated.

Are you sure you have already searched for the same problem?

Some people open new issues but they didn't search for something similar or for the same issue. Please, search for it using the GitHub issue search box or on the official inappwebview.dev website, or, also, using Google, StackOverflow, etc. before posting a new one. You may already find an answer to your problem!

If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. Please, make sure you have given me as much context as possible! Also, if you didn't already, post a code example that can replicate this issue.

In the meantime, you can already search for some possible solutions online! Because this plugin uses native WebView, you can search online for the same issue adding android WebView [MY ERROR HERE] or ios WKWebView [MY ERROR HERE] keywords.

Following these steps can save you, me, and other people a lot of time, thanks!