CleverTap / clevertap-android-sdk

CleverTap Android SDK
MIT License
80 stars 74 forks source link

ANR on Clevertap Sdk initialization (CleverTapAPI.getDefaultInstance) #666

Closed bhanu-rapido closed 1 month ago

bhanu-rapido commented 2 months ago

Describe the bug we are initializing the clevertap sdk from application class, and more users are facing a ANR on app startup only. method name we are calling is: CleverTapAPI.getDefaultInstance

To Reproduce

Expected behavior ANR should not happen, or provide a way to initialize on background thread

**Screens

Screenshot 2024-09-12 at 4 36 30 PM

ots/Logs**

Environment (please complete the following information):

Additional context com.rapido.rider_issue_020812ffe500edecedad0d092b35eb37_ANR_session_66E2C93C0064000170E7ED0B885C7CC6_DNE_0_v2_stacktrace.txt

CTLalit commented 2 months ago

@bhanu-rapido yes clevertap can be created on background thread in any standard android way. You can also use clevertap methods like post event and so on on background thread, event though it is not needed and we do all heavy lifting internally on background thread.

We have benchmarked clevertap instance creation and its mean is ~15ms and max is not more than 40ms.

Please raise a support ticket via this link. Clevertap can then help verify your integration and take any further steps, if required.

bhanu-rapido commented 2 months ago

this is how, we are initializing a clevertap sdk and geo-fencing on app startup. the whole block code can be moved to background thread on app startup?

Screenshot 2024-09-14 at 7 23 55 PM
bhanu-rapido commented 2 months ago

also i see the sdk parses the manifest file. have you benchmarked with 30-50 activities, few services, broadcast receiver and metadata ( as our app manifest file is very big) ?

Screenshot 2024-09-16 at 9 07 20 AM
CTLalit commented 1 month ago

@bhanu-rapido yes, you can move the code block in background thread which you have mentioned above. Did you get all the ANRs which always point only at manifest info? I suspect that there is some other part of your code which might be blocking main and this log is printed which does not point to actual problem (same can be confirmed if you check ANR console and find erratic line numbers in case clevertap is mentioned in stacktrace)

On a side note will try to add benchmark with large number of activities as you mentioned (please raise a support ticket incase you need help with it and someone from CleverTap will get in touch).