Firebase未报告与OkHttp相关的崩溃

在我面临的问题之后,我正在将我的代码从Google分析迁移到Firebase

  1. 一些自定义事件显示正确的值,而其他自定义事件虽然使用的代码在所有情况下都相同。 如果需要可以提供代码。

更新:上面解决了,我发送了大量数据,所以它只是省略了它们。

  1. 在使用OkHttp(使用Android网络库和Asynctask)之前,firebase在崩溃报告中显示正确的行号,但在使用OkHttp之后没有,我可以确认我已经上传了正确的映射文件,因为其他非OKHttp相关的崩溃被正确报告。

所以我的担忧不是例外,而是从哪里抛出?

OKhttp之前的Firebase崩溃报告

 Exception java.net.SocketTimeoutException: connect timed out java.net.PlainSocketImpl.socketConnect (PlainSocketImpl.java) java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java:334) java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java:196) java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java:178) java.net.SocksSocketImpl.connect (SocksSocketImpl.java:356) java.net.Socket.connect (Socket.java:586) com.android.okhttp.internal.Platform.connectSocket (Platform.java:113) com.android.okhttp.Connection.connectSocket (Connection.java:1432) com.android.okhttp.Connection.connect (Connection.java:1390) com.android.okhttp.Connection.connectAndSetOwner (Connection.java:1667) com.android.okhttp.OkHttpClient$1.connectAndSetOwner (OkHttpClient.java:133) com.android.okhttp.internal.http.HttpEngine.connect (HttpEngine.java:466) com.android.okhttp.internal.http.HttpEngine.sendRequest (HttpEngine.java:371) com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute (HttpURLConnectionImpl.java:503) com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse (HttpURLConnectionImpl.java:438) com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode (HttpURLConnectionImpl.java:567) com.package.MyClass$4.doInBackground (MyClass.java:168) com.package.MyClass$4.doInBackground (MyClass.java:161) android.os.AsyncTask$2.call (AsyncTask.java:304) java.util.concurrent.FutureTask.run (FutureTask.java:237) android.os.AsyncTask$SerialExecutor$1.run (AsyncTask.java:243) java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1133) java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:607) java.lang.Thread.run (Thread.java:762) 

OkHttp之后的Firebase崩溃报告

 Exception java.net.SocketTimeoutException: connect timed out java.net.PlainSocketImpl.socketConnect (PlainSocketImpl.java) java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java:334) java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java:196) java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java:178) java.net.SocksSocketImpl.connect (SocksSocketImpl.java:356) java.net.Socket.connect (Socket.java:586) okhttp3.internal.platform.AndroidPlatform.connectSocket (AndroidPlatform.java:69) okhttp3.internal.connection.RealConnection.connectSocket (RealConnection.java:238) okhttp3.internal.connection.RealConnection.connect (RealConnection.java:158) okhttp3.internal.connection.StreamAllocation.findConnection (StreamAllocation.java:256) okhttp3.internal.connection.StreamAllocation.findHealthyConnection (StreamAllocation.java:134) okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java:113) okhttp3.internal.connection.ConnectInterceptor.intercept (ConnectInterceptor.java:42) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:121) okhttp3.internal.cache.CacheInterceptor.intercept (CacheInterceptor.java:93) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:121) okhttp3.internal.http.BridgeInterceptor.intercept (BridgeInterceptor.java:93) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147) okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept (RetryAndFollowUpInterceptor.java:125) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:121) okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java:200) okhttp3.RealCall$AsyncCall.execute (RealCall.java:147) okhttp3.internal.NamedRunnable.run (NamedRunnable.java:32) java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1133) java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:607) java.lang.Thread.run (Thread.java:761) 

作为OkHttp实现的请求代码

 Request request = new Request.Builder().url(Uri.parse(serviceUrl).buildUpon().appendPath("test").toString()) .build(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(@NonNull Call call, @NonNull IOException e) { FirebaseCrash.report(e); } @Override public void onResponse(@NonNull Call call, @NonNull final Response response) throws IOException { } 

给您的OkHttpClient添加:

 client.connectTimeoutMillis(20000); // 20000 means 20 seconds give time here in milliseconds 

或者您也可以将其添加到客户端构建器中:

 clientBuilder.connectTimeout(60, TimeUnit.SECONDS); 

发生这种情况是因为当服务器的响应到达您时,您的请求超时。 提供您认为服务器可以响应的超时。

或者你也可以这样做,但我不确定:

 Request request = new Request.Builder().wait(long millisecondshere).url(Uri.parse(serviceUrl).buildUpon().appendPath("test").toString()) .build(); 

这是超时问题,

有两种可能性,

  1. 你检查并测试了你的连接。
  2. 最好不要设置任何连接超时,如果你设置选择最大时间,因为它会抛出一个错误,如果服务器在给定时间内没有响应..

防止SocketTimeoutException超出了我们的限制……有效处理它的一种方法是定义一个连接超时,然后使用try catch块来处理它….希望这将有助于将来面临同样问题的任何人。

您可以为HttpUrlConnection设置超时,例如,

 HttpUrlConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(8000);