Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase isn't reporting crashes related to OkHttp

I was migrating my code from Google analytics to Firebase, following problem I'm facing

  1. Some of the custom events show correct value while others not although code used are same in all cases. Can provide code if required.

Update : Above is solved, I was sending large data so its just omitted them.

  1. Prior to using OkHttp(using Android network library and Asynctask) firebase shows correct line number in crash reports but not after using OkHttp, I can confirm that I have uploaded correct mapping file as other non OKHttp related crashes are reported correctly.

So my concern is not exception but from where it is thrown?

Firebase crash report before OKhttp

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)

Firebase crash report after OkHttp

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)

As requested code for OkHttp implementation

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 {
}
like image 255
ingsaurabh Avatar asked Oct 07 '17 05:10

ingsaurabh


2 Answers

After initializing crashlytics in your base application with following code (Note this part is missing in Google's official documentation)

FirebaseApp.initializeApp(getApplicationContext());
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);

Call following function

FirebaseCrashlytics.getInstance().sendUnsentReports();

In this way you, on your next application start, unsent reports will be uploaded

You can use this link for crashlytics integration https://firebase.google.com/docs/crashlytics/get-started-new-sdk?platform=android&authuser=0

like image 80
striker Avatar answered Nov 06 '22 08:11

striker


To your OkHttpClient add :

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

or you can also add it to your client builder as:

clientBuilder.connectTimeout(60, TimeUnit.SECONDS);

This happens because when response of server reached to you, your request timed out. Give timeout what you think is feasible for your server to respond.

or you can also may be do with that too but I am not sure about that:

Request request = new Request.Builder().wait(long millisecondshere).url(Uri.parse(serviceUrl).buildUpon().appendPath("test").toString())
                    .build();
like image 39
Muhammad Saad Rafique Avatar answered Nov 06 '22 06:11

Muhammad Saad Rafique