Firebase isn't reporting crashes related to OkHttp

Related searches

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 {
}

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

Understand Realtime Database Billing, Learn how to set up Firebase for web apps. Try it now. Firebase documentation. Documentation to help you understand key topics in Firebase development. Firebase is deeply integrated with Google Cloud Platform, allowing you to use Google's Infrastructure-as-a-Service directly within your Firebase project. See Pricing FAQ for more information.

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();

Firebase | Google Developer Profile, Cloud Firestore is one of two Firebase tools that allows developers to set up and provision a back-end database as a service. Released in 2017,� Firebase Analytics is a Google-owned tool that attempts to analyze your app behavior so that you can make timely decisions and can grow your app to the next level. As you already know the market is full of analytics tools, but Google creates the best since it has the sole purpose of collecting data to earn money.

This is Timeout issue,

There are two possibilities,

  1. have you checked and tested your connection.
  2. better don't set any connection timeout,if you are setting chose maximum time, because it throws an error,if server didn't response within given time..

Preventing SocketTimeoutException is beyond our limit...One way to effectively handle it is to define a connection timeout and later handle it by using a try catch block.... hope this will help anyone in future who are facing the same issue.

You can set time out for HttpUrlConnection like,

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

Building a Real-World Web App With Vue.js & Firebase, Firebase is a serverless platform for unified development of applications for mobile devices and for the Web. It uses the NO-SQL structure as opposed to RDBMS� Firebase is Google’s mobile application development platform that encourages you to manufacture, improve, and become your application. As an organization (ChromeInfotech), bunches of customers are coming to us and asked about the best development platform for their software and the right wireframing for their mobile application.

Newest 'firebase' Questions, This is the first in a series of blog posts on Architecting your application with Firebase. Firebase isn't just any ordinary database. As a real-time,� i have the issue with firebase.util lib, as Rodrigo said i think is problem of the versión. Before: var ref = new Firebase('url'); Now: firebase.initializeApp(config); As the firebase object is defined differently it does not find it. In my case, I need to update the library to be compatible with version 3.0 of firebase.

Where does Firebase fit in your app?, If a user isn’t signed in with Google Play, it’s essential to sign in to enjoy the app that is an unlikely cause. Login with Google Using Firebase in Android Studio (Step by Step) Create a new project in Android Studio

Firebase This plugin brings push notifications, analytics, event tracking, crash reporting and more from Google Firebase to your Cordova project! Android and iOS supported (including iOS 10).

Comments
  • The stacktrace shows you started using OkHttp instead of Android's built-in version of OkHttp. What are you asking?
  • Android started using Okhttp internally starting from lollipop, as I have to support 4.0, I migrated to using Okhttp, as you can see in above logcat location of crash is mentioned as MyClass, but not in the latter version when I explicitly used OKhttp, I am asking the reason for this?
  • Please provide the sources for this. Before you were using an async task which is clear in the stacktrace. How is this call implemented now?
  • Updated the question with code although it just a simple call, my concern is not exception but from where it is thrown?
  • Thanks, but the question is location of crash is not provided when OkHttp is used