google / cronet-transport-for-okhttp

This package allows OkHttp and Retrofit users to use Cronet as their transport layer, benefiting from features like QUIC/HTTP3 support or connection migration.
Apache License 2.0
427 stars 31 forks source link

ANRs when loading Cronet Provider #28

Open adityameesho opened 11 months ago

adityameesho commented 11 months ago

Sharing some of the ANRs encountered when calling CronetProviderInstaller and when calling build method of CronetEngine.Builder and CronetInterceptor

There is one ANR happening due to System.loadLibrary being called on main thread by Play Services.

Is it safe to call the CronetProviderInstaller.installProvider() on a background thread?

anr_load_library.txt anr1.txt anr2.txt anr3.txt

edechamps-Google commented 11 months ago

Hi @adityameesho,

Initializing Cronet can be fairly expensive as it involves loading a non-trivial amount of Java code as well as the native library (which requires its own initialization as well). For this reason, it might indeed be a good idea to do it in a background thread to avoid blocking the UI on the loading process, which could potentially result in ANRs especially if the device is slow or starved of resources (e.g. during app startup).