Leanplum-Android-SDK icon indicating copy to clipboard operation
Leanplum-Android-SDK copied to clipboard

Fatal Exception: java.lang.NoClassDefFoundError: com.leanplum.internal.APIConfig

Open galacticappster04 opened this issue 2 years ago • 1 comments

Expected Behavior

  • Shouldn't crash

Actual Behavior

  • We received record on our Crashlytics regarding the following:
Fatal Exception: java.lang.NoClassDefFoundError: com.leanplum.internal.APIConfig
       at com.leanplum.internal.APIConfig.getInstance(APIConfig.java:59)
       at com.leanplum.internal.RequestSender.createArgsDictionary(RequestSender.java:211)
       at com.leanplum.internal.RequestSender.saveRequest(RequestSender.java:82)
       at com.leanplum.internal.RequestSender.sendSync(RequestSender.java:243)
       at com.leanplum.internal.RequestSender.access$000(RequestSender.java:37)
       at com.leanplum.internal.RequestSender$1.run(RequestSender.java:230)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:268)
       at android.os.HandlerThread.run(HandlerThread.java:67)

Steps to Reproduce the Problem

  1. No discernible reproduction steps as this is happens 100% in the background

Specifications

  • Version: 5.10.4
  • Platform: Android

galacticappster04 avatar Dec 07 '22 02:12 galacticappster04

@neonwarge04 I'm not sure why this error happens. Both classes RequestSender and APIConfig are located in the same module, so it is not because of mismatched versions. How often does this error occur and is it on some specific devices?

hborisoff avatar Dec 08 '22 13:12 hborisoff

By a lot @hborisoff, at least in our books. We are getting 247 crashes on 42 users.

Here are the stats

Devices

  • 53% Samsung
  • 19% Vivo
  • 13% Xiaomi
  • 7% Realme
  • 8% Other

Operating System 36% Android 11 29% Android 10 13% Android 12 10% Android 8 12% Other

Device States

  • 100% in background
  • 100% proximity on

We have plans to update 5.10.4 -> 6.0.0 and 6.0.0 to 7.0.0 but we are still not sure if this will fix the problem. We are working on the migration but this is a blind fix.

Any input is appreciated.

galacticappster04 avatar Dec 12 '22 02:12 galacticappster04

Let me know if you need more info. I updated op with all the crash stack trace. If you notice the following:

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.SharedPreferences android.content.Context.getSharedPreferences(java.lang.String, int)' on a null object reference
       at com.leanplum.internal.APIConfig.load(APIConfig.java:106)
       at com.leanplum.internal.APIConfig.<init>(APIConfig.java:55)
       at com.leanplum.internal.APIConfig.<clinit>(APIConfig.java:34)
       at com.leanplum.internal.APIConfig.getInstance(APIConfig.java:59)
       at com.leanplum.Leanplum.setAppIdForProductionMode(Leanplum.java:258)
       at com.leanplum.segment.LeanplumIntegration.<init>(LeanplumIntegration.java:65)
       at com.leanplum.segment.LeanplumIntegration$1.create(LeanplumIntegration.java:44)
       at com.segment.analytics.Analytics.performInitializeIntegrations(Analytics.java:1624)
       at com.segment.analytics.Analytics$2$1.run(Analytics.java:333)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:7814)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

It appears for whatever reason SharedPreferences is null.

galacticappster04 avatar Dec 12 '22 02:12 galacticappster04

@neonwarge04 The NullPointerException happens because Leanplum context is not yet set. Can you call Leanplum.setApplicationContext as soon as possible in your Application's onCreate method? This issue is fixed with newer SDK versions.

Is it possible that the ExceptionInInitializerError is because of the NullPointerException?

About the NoClassDefFound, I can't connect it to anything else, because the APIConfig can't be removed from Proguard, as it is used in a lot of places.

hborisoff avatar Dec 12 '22 07:12 hborisoff

Hello @hborisoff , thanks for the reply, we do already call this Leanplum.setApplicationContext(this) just before Leanplum.start. Also take note we have Segment integration as well and undergoes initialization. Can you please tell us how do we order the initialization?

Is there anything else I missed in the documentation regarding the proguard rule? This one is placed in our proguard-rules.pro:

########################################
## LeanPlum
########################################
-keepclassmembers class *
{
  @com.leanplum.annotations.* <fields>;
}
-keep class com.leanplum.** { *; }
-dontwarn com.leanplum.**
########################################

Our crash count on this is climbing up and we are preparing for patch it appears upgrading leanplum is a good bet.

galacticappster04 avatar Dec 14 '22 02:12 galacticappster04

@neonwarge04 Sorry, I just realised that you have issues with the Segment SDK and not the Android SDK. It is a known issue and was fixed with latest version. The fix was introducing this line that was missing before setting the keys.

hborisoff avatar Dec 14 '22 07:12 hborisoff

Thank you @hborisoff, I think we can close this now. I will reopen again if this shows up in our later version. Thank you!

galacticappster04 avatar Dec 15 '22 02:12 galacticappster04