Fix NoClassDefFoundError for DefaultJsonSerializer$LazyHolder in ProGuard/R8 release builds#530
Draft
Copilot wants to merge 1 commit into
Draft
Fix NoClassDefFoundError for DefaultJsonSerializer$LazyHolder in ProGuard/R8 release builds#530Copilot wants to merge 1 commit into
Copilot wants to merge 1 commit into
Conversation
…ng ProGuard/R8 keep rules Agent-Logs-Url: https://github.com/optimizely/android-sdk/sessions/b3341336-5cfc-4bda-a258-73558bcf3d85 Co-authored-by: muzahidul-opti <129880873+muzahidul-opti@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
muzahidul-opti
May 14, 2026 13:54
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
NoClassDefFoundError: com.optimizely.ab.event.internal.serializer.DefaultJsonSerializer$LazyHolderthat prevents experiment impression events and conversion/purchase events from being dispatched in minified release builds (Android SDK 5.1.1+).Root Cause
LogEvent.getBody()(called fromEventWorker.getData()) invokesDefaultJsonSerializer.getInstance(), which accessesDefaultJsonSerializer$LazyHolder.INSTANCEusing the initialization-on-demand holder (lazy initialization) pattern:proguard-rules.txtalready keepscom.optimizely.ab.event.internal.payload.**(the event payload model classes), but had no keep rule forcom.optimizely.ab.event.internal.serializer.**. R8/ProGuard therefore stripsDefaultJsonSerializerand its$LazyHolderinner class during the release build, causing aNoClassDefFoundErrorat runtime the first time an event is dispatched.Because the exception occurs before the HTTP request is made, no events reach the
/v1/eventsendpoint — explaining why impression and conversion events silently fail while a customEventHandlerthat manually serializes with Gson works fine.Changes
Added three ProGuard/R8 keep rules to
proguard-rules.txt(which is already wired asconsumerProguardFilesin theandroid-sdkmodule):-keep class ...DefaultJsonSerializer { *; }LogEvent.getBody()-keep class ...DefaultJsonSerializer$LazyHolder { *; }NoClassDefFoundError-keep class ...GsonSerializer { *; }DefaultJsonSerializer.create()selects at runtime on Android (Gson is bundled; Jackson is not)Testing
This is a ProGuard-only configuration change. The fix can be verified by building a minified release APK (
minifyEnabled true) and confirming:NoClassDefFoundErrorin logcat whendecide()ortrack()is called.EventHandler.