Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NullPointerException in Cordova App reported by Fabric SDK

Tags:

I am using Ionic framework to build the hybrid Android app and the app works fine. I am using Fabric Crash analytics plugin and its reporting the crashes of the app.

I am getting the below crash details very often and not sure what's the reason for the same. I am not sure what would be the starting point to start analysizing 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 it related to any plugin or any issue in Ionic or Cordvoa? Any help or advise would be helpful.

like image 807
Purus Avatar asked Mar 26 '16 18:03

Purus


1 Answers

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

It's reproduced only on Android 4.1.2, 4.2.2, 4.3.

I have reproduced the bug:

  1. open WebView with content that contain javascript functions;
  2. open new WebView and close it;
  3. disable network (wifi and mobile) as soon as possible;
  4. return to app and show stacktrace.

I found a solution:

I'm not using CordovaActivity in my app. I'm using CordovaInterface. PluginManager associated with deleted WebView continues to call its methods. So I manual call WebView.handleDestroy() to destroy PluginManager.

In my Fragment:

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

    super.onDestroy();
}

Update: It's reproduced when you destroy WebView, but PluginManager continues to live and sends javascripts events to subscribers (WebViews). Because I call WebView.handleDestroy().

like image 69
ilyamuromets Avatar answered Oct 12 '22 11:10

ilyamuromets