clevertap-android-sdk icon indicating copy to clipboard operation
clevertap-android-sdk copied to clipboard

ANR on ActivityLifecycleCallback.register

Open sonusourav-rapido opened this issue 9 months ago • 1 comments

Describe the bug We are getting ANR reports in Firebase Crashlytics and stack trace points to the below code snippet

com.clevertap.android.sdk.CleverTapAPI.getDebugLevel (CleverTapAPI.java) com.clevertap.android.sdk.Logger.getStaticDebugLevel (Logger.java:204) com.clevertap.android.sdk.Logger.i (Logger.java:40) com.clevertap.android.sdk.ActivityLifecycleCallback.register (ActivityLifecycleCallback.java:82) com.clevertap.android.sdk.ActivityLifecycleCallback.register (ActivityLifecycleCallback.java:92) com.rapido.passenger.RapidoApplication.initCleverTapSdk (RapidoApplication.kt:128) com.rapido.passenger.RapidoApplication.onCreate (RapidoApplication.kt:62) android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1192) android.app.ActivityThread.handleBindApplication (ActivityThread.java:7294) android.app.ActivityThread.access$1700 (ActivityThread.java:299) android.app.ActivityThread$H.handleMessage (ActivityThread.java:2184) android.os.Handler.dispatchMessage (Handler.java:106) android.os.Looper.loop (Looper.java:264) android.app.ActivityThread.main (ActivityThread.java:8312) java.lang.reflect.Method.invoke (Native method) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:632) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1049)

Screenshots/Logs

Image

cleverTap_anr.txt

Environment (please complete the following information):

  • Device: Across Devices
  • OS: Across OS Versions
  • CleverTap SDK Version 7.0.0
  • Android Studio Version: Android Studio Koala Feature Drop | 2024.1.2 Patch 1 Build #AI-241.19072.14.2412.12360217, built on September 12, 2024

sonusourav-rapido avatar Mar 30 '25 05:03 sonusourav-rapido

@sonusourav-rapido

  1. Can you confirm if ActivityLifecycleCallback.register is called before super.onCreate() of your application class?
  2. On internal benchmarking the above operation took merely ~5ms on an average. It could be possible that the ANR is related to slow startup time and the logs are misleading. Can you confirm the same by
val timeTaken = measureTimeMillis {
            ActivityLifecycleCallback.register(this)
        }
// log timetaken
  1. There is no StrictModeViolation either which directly pertains to the above operation.

Anush-Shand avatar Apr 01 '25 07:04 Anush-Shand

@Anush-Shand

  1. Yes, ActivityLifecycleCallback.register get called before super.onCreate().
  2. It showed ~28 ms for me. But not able to understand if the clevertap initialisation is the first thing happening on our application, what else related to our code could be causing that, and pointing to clevertap 🤔
  3. There is no StrictModeViolation

sonusourav-rapido avatar Apr 23 '25 19:04 sonusourav-rapido

@sonusourav-rapido Since the ActivityLifecycleCallback.register(this) takes ~28ms and there are no StrictModeViolations reported from the SDK side it points to the possibility that the clevertap code is simply a false alarm and there is some other piece of slow running code leading to the ANR

Is there anything needed from the Clevertap team on this?

Anush-Shand avatar Jul 21 '25 09:07 Anush-Shand

Closing this due to inactivity

Anush-Shand avatar Sep 30 '25 11:09 Anush-Shand