flutter_inappwebview icon indicating copy to clipboard operation
flutter_inappwebview copied to clipboard

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo

Open dkunkic opened this issue 3 years ago • 13 comments

Environment

Technology Version
Flutter version 2.0.3
Plugin version 5.3.0
Android version 8 - 11

Device information: Samsung - mostly Galaxy A51, Galaxy A50 Huawei Mate 10 Lite, LG Velvet, Sony Xperia XZ Premium

Description

I don't know how to reproduce it, but I get this error on Firebase Crashlytics.

Current behavior: Here is the log from the Firebase

   Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeCustomTabsActivity}: java.lang.NullPointerException: Attempt to read from field 'com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeSafariBrowserManager.plugin' on a null object reference
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3556)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3703)
   at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
   at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
   at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2216)
   at android.os.Handler.dispatchMessage(Handler.java:107)
   at android.os.Looper.loop(Looper.java:237)
   at android.app.ActivityThread.main(ActivityThread.java:7948)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
   

   Caused by java.lang.NullPointerException: Attempt to read from field 'com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeSafariBrowserManager.plugin' on a null object reference
   at com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeCustomTabsActivity.onCreate(ChromeCustomTabsActivity.java:42)
   at android.app.Activity.performCreate(Activity.java:7955)
   at android.app.Activity.performCreate(Activity.java:7944)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3531)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3703)
   at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
   at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
   at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2216)
   at android.os.Handler.dispatchMessage(Handler.java:107)
   at android.os.Looper.loop(Looper.java:237)
   at android.app.ActivityThread.main(ActivityThread.java:7948)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

dkunkic avatar Apr 14 '21 12:04 dkunkic

👋 @dkunkic

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!

github-actions[bot] avatar Apr 14 '21 12:04 github-actions[bot]

It should be impossible that when creating an instance of the ChromeSafariBrowser, the java.lang.NullPointerException: Attempt to read from field 'com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeSafariBrowserManager.plugin' on a null object reference could happen. It doesn't make any sense to me, as a ChromeSafariBrowserManager native class is always instantiated before starting a new ChromeCustomTabsActivity, otherwise, it couldn't do that. Could you post the code you are using about the ChromeSafariBrowser class? How are you using it? Where do you call it? Thanks

pichillilorenzo avatar Apr 14 '21 12:04 pichillilorenzo

I'm using InAppWebView as a widget, and then in shouldOverrideUrlLoading method, depending on which url I get, I open the browser.

               child: 
                     InAppWebView(

                          initialUrlRequest: URLRequest(
                              url: Uri.parse(UrlConstants.liveTickerUrl)),

                          initialOptions: InAppWebViewGroupOptions(
                              android: AndroidInAppWebViewOptions(
                                  verticalScrollbarPosition:
                                      AndroidVerticalScrollbarPosition
                                          .SCROLLBAR_POSITION_RIGHT),
                              crossPlatform: InAppWebViewOptions(
                                supportZoom: false,
                                useShouldOverrideUrlLoading: true,
                              )),

                          onWebViewCreated: (controller) {
                            webView = controller;
                            // Hide Progress Indicator
                            loadingIndicatorVisible.value = false;
                          },

                          shouldOverrideUrlLoading:
                              (controller, navigationActionPolicy) async {
                            var url = navigationActionPolicy.request.url!;

                            if (url
                                .toString()
                                .trim()
                                .contains(UrlConstants.aditionUrl.trim())) {
                              chromeSafariBrowser.open(url: url);
                              return NavigationActionPolicy.CANCEL;
                            }

                            return NavigationActionPolicy.ALLOW;
                          }),
Screenshot 2021-04-14 at 15 12 07 Screenshot 2021-04-14 at 15 12 48

dkunkic avatar Apr 14 '21 13:04 dkunkic

Hello, I've got the same crash on Android version 7 using ChromeSafariBrowser.

The crash intervene when the host is blocked by an htaccess but working otherwise.

2697-2697/my.app.dev E/AndroidRuntime: FATAL EXCEPTION: main
    Process: my.app.dev, PID: 2697
    java.lang.RuntimeException: Unable to start activity ComponentInfo{my.app.dev/com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeCustomTabsActivity}: java.lang.NullPointerException: Attempt to read from field 'com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeSafariBrowserManager.plugin' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
     Caused by: java.lang.NullPointerException: Attempt to read from field 'com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeSafariBrowserManager.plugin' on a null object reference
       at com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeCustomTabsActivity.onCreate(ChromeCustomTabsActivity.java:52)
        at android.app.Activity.performCreate(Activity.java:6942)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
        at android.app.ActivityThread.-wrap14(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6682) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

My code :

    ChromeSafariBrowser _browser = new ChromeSafariBrowser();
    ...
    await _browser.open(
        url: uri,
        options: ChromeSafariBrowserClassOptions(
          android: AndroidChromeCustomTabsOptions(
            addDefaultShareMenuItem: false,
            enableUrlBarHiding: true,
            showTitle: false,
            toolbarBackgroundColor: Colors.black,
          ),
          ios: IOSSafariOptions(barCollapsingEnabled: true, dismissButtonStyle: IOSSafariDismissButtonStyle.CANCEL),
        ),
      );

MathieuBa avatar Apr 26 '21 07:04 MathieuBa

Same #794

shinsenter avatar May 05 '21 23:05 shinsenter

Hello, I've got the same crash on Android version 7 using ChromeSafariBrowser.

The crash intervene when the host is blocked by an htaccess but working otherwise.

2697-2697/my.app.dev E/AndroidRuntime: FATAL EXCEPTION: main
    Process: my.app.dev, PID: 2697
    java.lang.RuntimeException: Unable to start activity ComponentInfo{my.app.dev/com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeCustomTabsActivity}: java.lang.NullPointerException: Attempt to read from field 'com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeSafariBrowserManager.plugin' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
     Caused by: java.lang.NullPointerException: Attempt to read from field 'com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeSafariBrowserManager.plugin' on a null object reference
       at com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeCustomTabsActivity.onCreate(ChromeCustomTabsActivity.java:52)
        at android.app.Activity.performCreate(Activity.java:6942)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
        at android.app.ActivityThread.-wrap14(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6682) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

My code :

    ChromeSafariBrowser _browser = new ChromeSafariBrowser();
    ...
    await _browser.open(
        url: uri,
        options: ChromeSafariBrowserClassOptions(
          android: AndroidChromeCustomTabsOptions(
            addDefaultShareMenuItem: false,
            enableUrlBarHiding: true,
            showTitle: false,
            toolbarBackgroundColor: Colors.black,
          ),
          ios: IOSSafariOptions(barCollapsingEnabled: true, dismissButtonStyle: IOSSafariDismissButtonStyle.CANCEL),
        ),
      );

Can you please give me more information on how to reproduce the bug. Thanks!

dkunkic avatar May 06 '21 14:05 dkunkic

Alright, I tried to reproduce it with the minimum application possible and succeed, but it's a problem really specific, don't know if you want to pass a lot of time on it and don't know if you will be able to reproduce. I will explain.

I used your example on ChromeSafariBrowser and get it working with https://flutter.dev/

Then, I used a local url (I can't give it to you, sorry) totally blocked behind an htaccess. Still working.

Where the crash come is when the url (still a local one) is allowed by the htaccess, but other data (css, js, ...) are all blocked.

I tried it on two differents configurations:

  • Android API 30 (simulator) --> Worked like a charm
  • Android API 24 (Samsung Galaxy S6) --> Crash

For now, that's all the information that I can give you. But don't hesitate to ask more :)

MathieuBa avatar May 07 '21 14:05 MathieuBa

The app crashes if chrome is not installed on the device. That happens on Samsung devices. #1009

frankteller-de avatar Oct 13 '21 11:10 frankteller-de

I'm seeing the same issue reported in crashlytics on a variety of devices. Has there been any progress identifying the root cause @pichillilorenzo Looking at the source for ChromeCustomTabsActivity I can see there's a lot of potential for this to be returned as null. I'm not sure how this is set in the Bundle, but it seems if the managerId is not set this will result in an NPE.

    Bundle b = getIntent().getExtras();
    assert b != null;
    id = b.getString("id");

    String managerId = b.getString("managerId");
    manager = (ChromeSafariBrowserManager) ChromeSafariBrowserManager.shared.get(managerId);

JasonSheedy avatar Jan 17 '22 05:01 JasonSheedy

same error here on a variety of android devices. I've put a lot of logs to send to crashlytics and I got none of them. And then I realized that it's happing when the app is launching. And I just started ta have this error more frequently last couple of weeks.

image

diegoalex avatar Mar 22 '22 15:03 diegoalex

is there any workaround for this ?

andredealmei avatar May 04 '22 18:05 andredealmei

Have you tried the latest version of the plugin? There shouldn't be that error anymore

pichillilorenzo avatar May 04 '22 21:05 pichillilorenzo

@diegoalex Hello, I would like to follow up your issue. We have been getting the same logs as you recently. Have you updated to the latest version? Do you still get the same crash log?

Thank you in advance.

sarunyool avatar Sep 12 '22 08:09 sarunyool

FATAL EXCEPTION: main Process: com.example.demonews, PID: 30777 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.demonews/com.example.demonews.ui.MainActivity}: android.view.InflateException: Binary XML file line #75 in com.example.demonews:layout/activity_main: Binary XML file line #75 in com.example.demonews:layout/activity_main: Error inflating class fragment at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3766) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3914) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2417) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loopOnce(Looper.java:238) at android.os.Looper.loop(Looper.java:357) at android.app.ActivityThread.main(ActivityThread.java:8194) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:957) Caused by: android.view.InflateException: Binary XML file line #75 in com.example.demonews:layout/activity_main: Binary XML file line #75 in com.example.demonews:layout/activity_main: Error inflating class fragment Caused by: android.view.InflateException: Binary XML file line #75 in com.example.demonews:layout/activity_main: Error inflating class fragment Caused by: kotlin.UninitializedPropertyAccessException: lateinit property viewModel has not been initialized at com.example.demonews.ui.MainActivity.getViewModel(MainActivity.kt:20) at com.example.demonews.ui.Fragments.BreakingNewsFragment.onViewCreated(BreakingNewsFragment.kt:28) at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3147) at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:588) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:272) at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:114) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1455) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3034) at androidx.fragment.app.FragmentManager.dispatchViewCreated(FragmentManager.java:2945) at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3148) at androidx.fragment.app.FragmentStateManager.ensureInflatedView(FragmentStateManager.java:410) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:271) at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:142) at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:136) at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:247) at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:226) at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1073) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1001) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088) at android.view.LayoutInflater.inflate(LayoutInflater.java:686) at android.view.LayoutInflater.inflate(LayoutInflater.java:538) at com.example.demonews.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:66) 2024-02-25 22:23:01.823 30777-30777 AndroidRuntime com.example.demonews E at com.example.demonews.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:60) at com.example.demonews.ui.MainActivity.onCreate(MainActivity.kt:24) at android.app.Activity.performCreate(Activity.java:8575) at android.app.Activity.performCreate(Activity.java:8554) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1419) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3747) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3914) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2417) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loopOnce(Looper.java:238) at android.os.Looper.loop(Looper.java:357) at android.app.ActivityThread.main(ActivityThread.java:8194) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:957) 2024-02-25 22:23:01.834 30777-30777 Process com.example.demonews I Sending signal. PID: 30777 SIG: 9

SanguleAKB avatar Feb 25 '24 16:02 SanguleAKB

I found this error continuously.

SanguleAKB avatar Feb 25 '24 17:02 SanguleAKB