'ANR and crash in an android app, Android 8(.1), 90% Huawei devices

Since a recent android app update, I'm facing an ANR and a crash issue, that mainly appear on Huawei devices running Android 8. (I managed to reproduce the ANR on an Honor 7x, Android 8.0).

  • According to the Google Play Console Logs, the crash occurs only on Android 8.1, and by 93% on Huawei devices.
  • On the other hand, the ANR (again mainly on Huawei devices) does not appear on Android 8.1 (like the crash mentioned above), but almost exclusively on Android 8.0.

The two issues seem to be connected - I guess that the cause is the same, but with different results on Android 8.0 and Android 8.1.

Concerning the cause:

  • Recently, a video ad library (https://www.teads.tv/) has been added to the app, and I think that it is causing the problems.
  • Without loading these ads, no crashes occur.

However, I could not find anything related to this issue on the internet. I'm wondering, if anything can actually be done about this, since I have no access to the library and no clue, why this occurs almost only on Huawei devices.

I'm also contacting the authors of the video ad library, but maybe someone is facing/has solved similar issues.


Console log of the Android 8.1-Crash

java.lang.RuntimeException: 
  at com.android.org.conscrypt.ConscryptFileDescriptorSocket.newSsl (ConscryptFileDescriptorSocket.java:161)
  at com.android.org.conscrypt.ConscryptFileDescriptorSocket.<init> (ConscryptFileDescriptorSocket.java:152)
  at com.android.org.conscrypt.OpenSSLSocketFactoryImpl.createSocket (OpenSSLSocketFactoryImpl.java:155)
  at okhttp3.internal.connection.RealConnection.connectTls (RealConnection.java:307)
  at okhttp3.internal.connection.RealConnection.establishProtocol (RealConnection.java:282)
  at okhttp3.internal.connection.RealConnection.connect (RealConnection.java:167)
  at okhttp3.internal.connection.StreamAllocation.findConnection (StreamAllocation.java:257)
  at okhttp3.internal.connection.StreamAllocation.findHealthyConnection (StreamAllocation.java:135)
  at okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java:114)
  at okhttp3.internal.connection.ConnectInterceptor.intercept (ConnectInterceptor.java:42)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:121)
  at okhttp3.internal.cache.CacheInterceptor.intercept (CacheInterceptor.java:93)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:121)
  at okhttp3.internal.http.BridgeInterceptor.intercept (BridgeInterceptor.java:93)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147)
  at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept (RetryAndFollowUpInterceptor.java:126)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:121)
  at okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java:200)
  at okhttp3.RealCall$AsyncCall.execute (RealCall.java:147)
  at okhttp3.internal.NamedRunnable.run (NamedRunnable.java:32)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
  at java.lang.Thread.run (Thread.java:784)
Caused by: javax.net.ssl.SSLException: 
      at com.android.org.conscrypt.NativeCrypto.SSL_new (NativeCrypto.java)
      at com.android.org.conscrypt.SslWrapper.newInstance (SslWrapper.java:58)
      at com.android.org.c`enter code here`onscrypt.ConscryptFileDescriptorSocket.newSsl (ConscryptFileDescriptorSocket.java:159)
      at com.android.org.conscrypt.ConscryptFileDescriptorSocket.<init> (ConscryptFileDescriptorSocket.java:152)
      at com.android.org`enter code here`.conscrypt.OpenSSLSocketFactoryImpl.createSocket (OpenSSLSocketFactoryImpl.java:155)
      at okhttp3.internal.connection.RealConnection.connectTls (RealConnection.java:307)
      at okhttp3.internal.connection.RealConnection.establishProtocol (RealConnection.java:282)
      at okhttp3.internal.connection.RealConnection.connect (RealConnection.java:167)
      at okhttp3.internal.connection.StreamAllocation.findConnection (StreamAllocation.java:257)
      at okhttp3.internal.connection.StreamAllocation.findHealthyConnection (StreamAllocation.java:135)
      at okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java:114)
      at okhttp3.internal.connection.ConnectInterceptor.intercept (ConnectInterceptor.java:42)
      at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147)
      at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:121)
      at okhttp3.internal.cache.CacheInterceptor.intercept (CacheInterceptor.java:93)
      at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147)
      at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:121)
      at okhttp3.internal.http.BridgeInterceptor.intercept (BridgeInterceptor.java:93)
      at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147)
      at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept (RetryAndFollowUpInterceptor.java:126)
      at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147)
      at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:121)
      at okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java:200)
      at okhttp3.RealCall$AsyncCall.execute (RealCall.java:147)
      at okhttp3.internal.NamedRunnable.run (NamedRunnable.java:32)
      at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
      at java.lang.Thread.run (Thread.java:784)

Posting the ANR logs probably would not be very useful, or would it?



Solution 1:[1]

There looks like a similar bug reported against OkHttp and they concluded it was caused by resource exhaustion, causing http not to be able to open a file handle.

I'd guess that the video Ads library is opening too many files and not closing them properly, or something like that. It sounds like the solution is to use a different Ads library with better code.

Solution 2:[2]

In Android 8.1, try replacing Provider to fix it

  • implementation 'org.conscrypt:conscrypt-android:2.5.2'

Check out the latest version at https://github.com/google/conscrypt#android

  • fix it in Application static method
static {
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O_MR1) {
        Security.insertProviderAt(Conscrypt.newProvider(), 1);
        Log.e("sslProvider", SSLSocketFactory.getDefault().getClass().getName());
    }
}

Seeing the log sslProvider: org.conscrypt.OpenSSLSocketFactoryImpl means success

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nick Fortescue
Solution 2 iMeiji