NullPointerException in a Cordova application introduced by the Fabric SDK

I use the Ionic framework to create a hybrid Android app, and the app works great. I use the Fabric Crash analytics plugin and report application crashes.

I often get crash data below and don’t know what the reason is the same. I'm not sure what will be the starting point for starting an analysis of this.

Fatal Exception: java.lang.NullPointerException at android.webkit.WebViewClassic.setNetworkAvailable(WebViewClassic.java:4224) at android.webkit.WebView.setNetworkAvailable(WebView.java:731) at org.apache.cordova.engine.SystemWebViewEngine$1.setNetworkAvailable(SystemWebViewEngine.java:112) at org.apache.cordova.NativeToJsMessageQueue$OnlineEventsBridgeMode$2.run(NativeToJsMessageQueue.java:340) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5319) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) at dalvik.system.NativeStart.main(NativeStart.java) 

Is this related to any plugin or any problem in Ionic or Cordvoa? Any help or recommendations would be helpful.

+5
source share
3 answers

I have the same problem. I also use Crashlytics Cordova and Fabric.

It only plays on Android 4.1.2, 4.2.2, 4.3.

I reproduced the error:

  • open a WebView with content containing javascript functions;
  • open a new WebView and close it;
  • disconnect the network (Wi-Fi and mobile) as soon as possible;
  • return to the application and show stacktrace.

I found a solution:

I do not use CordovaActivity in my application. I am using CordovaInterface. The PluginManager associated with the remote WebView continues to call its methods. Therefore, I manually call WebView.handleDestroy () to destroy the PluginManager.

In my fragment:

 @Override public void onDestroy() { if (webView != null) { webView.handleDestroy(); webView.destroy(); webView = null; } super.onDestroy(); } 

Update: It plays when the WebView is destroyed, but the PluginManager continues to live and sends javascripts events to subscribers (WebViews). Because I am calling WebView.handleDestroy ().

+2
source

Could you catch the exception? Edit this file:

/platforms/android/CordovaLib/src/org/apache/cordova/engineChange/SystemWebViewEngine.java

And change it

 webView.setNetworkAvailable(value); 

to that

 import java.lang.NullPointerException; ... try { webView.setNetworkAvailable(value); } catch (NullPointerException e) { Log.d(TAG, "webView.setNetworkAvailable called after destroy"); } 

This is actually not a solution, but given the complexity of playback locally, this may be an option.

+2
source

My solution was in SystemWebViewEngine.java.

  • change protected final SystemWebView webView; on protected SystemWebView webView;

  • in destroy() after

if (receiver != null) { try { webView.getContext().unregisterReceiver(receiver); } catch (Exception e) { Log.e(TAG, "Error unregistering configuration receiver: " + e.getMessage(), e); } }

add

webView = null;

  1. Replace webView.setNetworkAvailable(value); on the

    if (webView != null) webView.setNetworkAvailable(value);

0
source

Source: https://habr.com/ru/post/1245825/


All Articles