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.
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:
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().
You could swallow the exception? Edit this file:
/platforms/android/CordovaLib/src/org/apache/cordova/engineChange/SystemWebViewEngine.java
And change this
webView.setNetworkAvailable(value);
to this
import java.lang.NullPointerException;
...
try {
webView.setNetworkAvailable(value);
}
catch (NullPointerException e) {
Log.d(TAG, "webView.setNetworkAvailable called after destroy");
}
Not really a solution, but given the difficulty in reproducing locally, it may be an option to consider.
My solution was in SystemWebViewEngine.java.
change protected final SystemWebView webView;
to protected SystemWebView webView;
in destroy()
method 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;
Replace webView.setNetworkAvailable(value);
with
if (webView != null) webView.setNetworkAvailable(value);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.