[英]NullPointerException in Cordova App reported by Fabric SDK
I am using Ionic framework to build the hybrid Android app and the app works fine. 我正在使用Ionic框架来构建混合Android应用程序,该应用程序运行正常。 I am using Fabric Crash analytics plugin and its reporting the crashes of the app.
我正在使用Fabric Crash analytics插件并报告应用程序的崩溃。
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? 它与Ionic或Cordvoa中的任何插件或任何问题有关吗? Any help or advise would be helpful.
任何帮助或建议都会有所帮助。
I have the same problem. 我也有同样的问题。 I also use Cordova and Fabric Crashlytics.
我也使用Cordova和Fabric Crashlytics。
It's reproduced only on Android 4.1.2, 4.2.2, 4.3. 它仅在Android 4.1.2,4.2.2,4.3上重现。
I have reproduced the bug: 我已经复制了这个bug:
I found a solution: 我找到了解决方案:
I'm not using CordovaActivity in my app. 我没有在我的应用程序中使用CordovaActivity。 I'm using CordovaInterface.
我正在使用CordovaInterface。 PluginManager associated with deleted WebView continues to call its methods.
与已删除的WebView关联的PluginManager继续调用其方法。 So I manual call WebView.handleDestroy() to destroy PluginManager.
所以我手动调用WebView.handleDestroy()来销毁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). 更新:当您销毁WebView时会重现它,但PluginManager会继续存在并将javascripts事件发送给订阅者(WebViews)。 Because I call WebView.handleDestroy().
因为我调用了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. 我的解决方案是在SystemWebViewEngine.java中。
change protected final SystemWebView webView;
更改
protected final SystemWebView webView;
to protected SystemWebView webView;
protected SystemWebView webView;
in destroy()
method after 在
destroy()
方法之后
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);
替换
webView.setNetworkAvailable(value);
with 同
if (webView != null) webView.setNetworkAvailable(value);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.