Skip to content

fix(android): declare okhttp-android runtime dep and add CTEntry.imageURL [NT-3807] - #406

Merged
Felipe Mamud (fmamud) merged 1 commit into
mainfrom
NT-3807-android-okhttp-runtime-fix
Aug 3, 2026
Merged

fix(android): declare okhttp-android runtime dep and add CTEntry.imageURL [NT-3807]#406
Felipe Mamud (fmamud) merged 1 commit into
mainfrom
NT-3807-android-okhttp-runtime-fix

Conversation

@fmamud

Copy link
Copy Markdown
Contributor

Follow-up to #395.

Summary

  • Declare com.squareup.okhttp3:okhttp-android:5.1.0 directly in packages/android/ContentfulOptimization/build.gradle.kts. The prior PR set contentful.java to compileOnly with okhttp-jvm excluded to avoid a duplicate-class conflict, but the transitive bump left the parent okhttp:5.x (KMP metadata only) on the graph — consumers crashed at launch with ClassNotFoundException: okhttp3.OkHttpClient on the first line that touched the SDK.
  • Align implementations/android-sdk/shared and implementations/android-sdk/compose from okhttp:4.12.0 to okhttp-android:5.1.0. With both variants aligned on 5.x, the ref-impl no longer hits the duplicate-class packaging failure and no consumer-side packaging.resources.excludes workaround is needed. Verified :compose:assembleDebug and :views:assembleDebug both BUILD SUCCESSFUL without any excludes.
  • Add CTEntry.imageURL: String? extension property. Reads the linked-asset URL from a Contentful image field and prepends https: to protocol-relative //images.ctfassets.net/... URLs so Android image loaders (Coil/Glide) can consume it.
  • README + integration guides updated with a short note explaining that consumers who declare okhttp directly should use okhttp-android:5.x for alignment. Internal SDK knowledge base updated with the runtime-dep fact and the new extension property.

Test plan

  • pnpm android:test — BUILD SUCCESSFUL, 3 new CTEntry.imageURL unit tests pass (protocol-relative rewrite, absolute URL passthrough, null-safe missing fields).
  • pnpm lint — clean.
  • pnpm format:check — clean.
  • ./gradlew :compose:assembleDebug (Android reference impl) — BUILD SUCCESSFUL without any packaging excludes.
  • ./gradlew :views:assembleDebug (Android reference impl) — BUILD SUCCESSFUL without any packaging excludes.
  • Downstream: rebuild a consuming app with only implementation("com.contentful.java:optimization-android:<version>") (no okhttp-android override, no packaging excludes) and confirm MainActivity launches without ClassNotFoundException.

🤖 Generated with Claude Code

…eURL [NT-3807]

Consumers of the Android SDK hit `ClassNotFoundException: okhttp3.OkHttpClient`
at launch because contentful.java transitively bumps okhttp to 5.1.0 (whose
parent module is KMP metadata only) with `okhttp-jvm` excluded — leaving no
concrete okhttp variant on the runtime classpath. Declare
`com.squareup.okhttp3:okhttp-android:5.1.0` directly so it lands there.

Version-aligning to okhttp-android 5.x also removes the duplicate-class
packaging failure consumers were hitting from a mixed 4.x/5.x classpath, so
the reference implementation apps no longer need `packaging.resources.excludes`
workarounds. Update the ref-impl `shared` and `compose` modules to the same
`okhttp-android:5.1.0` artifact.

Add `CTEntry.imageURL: String?` extension property that resolves the linked
asset URL and prepends `https:` to protocol-relative Contentful Asset URLs
(Android image loaders reject the scheme-less form).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@fmamud
Felipe Mamud (fmamud) merged commit b175d07 into main Aug 3, 2026
40 checks passed
@fmamud
Felipe Mamud (fmamud) deleted the NT-3807-android-okhttp-runtime-fix branch August 3, 2026 16:05
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.

2 participants