Skip to content

fix: keep gson/okhttp class names in consumer ProGuard rules#20

Merged
Fiona2016 merged 1 commit into
publishfrom
fix/consumer-keep-gson-okhttp
Jun 9, 2026
Merged

fix: keep gson/okhttp class names in consumer ProGuard rules#20
Fiona2016 merged 1 commit into
publishfrom
fix/consumer-keep-gson-okhttp

Conversation

@Fiona2016

Copy link
Copy Markdown
Collaborator

Problem

A minified (R8) host app crashed at SDK init with:

FlashCat SDK initialization failed because of missing dependencies: Gson

It only happened in minified release builds, not debug.

Root cause

checkRuntimeDependencies() resolves com.google.gson.Gson and okhttp3.OkHttpClient
via Class.forName(...). With no keep rule, R8 was free to rename/strip those classes,
so the string-literal lookup failed at runtime and the SDK threw.

Fix

Ship consumer keep rules (bundled in the AAR via consumerProguardFiles) so the
reflective dependency check still resolves under R8:

-keep class com.google.gson.** { *; }
-keep class okhttp3.OkHttpClient { *; }

Host apps must still declare gson/okhttp themselves (they are compileOnly),
matching upstream Datadog.

Adds ConsumerRulesTest as a guard that these keeps stay present in consumer-rules.pro.

Verification

  • ./gradlew :dd-sdk-android-core:testDebugUnitTestConsumerRulesTest passes.
  • Target release: 0.4.1 (tag-driven).

🤖 Generated with Claude Code

A minified (R8) host app crashed at SDK init with "missing dependencies: Gson":
checkRuntimeDependencies() resolves com.google.gson.Gson and okhttp3.OkHttpClient
via Class.forName, and with no keep rule R8 was free to rename/strip those classes.

Ship consumer keep rules (bundled in the AAR) so the reflective dependency check
still resolves in minified release builds. Host apps must still declare gson/okhttp
themselves since they are compileOnly, matching upstream Datadog.

Add ConsumerRulesTest as a guard for the keep rules.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Fiona2016 Fiona2016 merged commit 932028e into publish Jun 9, 2026
2 of 5 checks passed
@Fiona2016 Fiona2016 deleted the fix/consumer-keep-gson-okhttp branch June 9, 2026 15:18
Fiona2016 added a commit that referenced this pull request Jun 10, 2026
Document the consumer ProGuard keep-rule fix (#20) that prevents the
"missing dependencies: Gson" startup crash on R8-minified host apps.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant