-
Notifications
You must be signed in to change notification settings - Fork 62
Fix Square.OkHttp3 5.0.0+ by creating separate okhttp-android package with type forwarders for backward compatibility #1239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: mattleibow <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are lots of errors:
<---
---> (Inner Exception #9) System.Exception:
No matching artifact config found for:
com.squareup.okhttp3:okhttp:4.12.0
to satisfy dependency of:
com.squareup.retrofit2:retrofit:3.0.0
Please add following json snippet to config.json:
{
"groupId": "com.squareup.okhttp3",
"artifactId": "okhttp",
"version": "4.12.0",
"nugetVersion": "CHECK PREFIX 4.12.0",
"nugetId": "CHECK NUGET ID",
"dependencyOnly": true/false
}
…ncies Co-authored-by: jonathanpeppers <[email protected]>
... Fixed the dependency resolution error by creating separate packages:
This ensures all dependencies resolve while providing the correct Android implementation in a separate NuGet package. Commit: dc5482d |
Co-authored-by: jonathanpeppers <[email protected]>
…ndroid Co-authored-by: jonathanpeppers <[email protected]>
Do we need type forwarding for the assemblies that already exist? Can we use the transforms from okhttp3 so the spin status the same? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot can you also bump the nugetVersion
by .1
(fourth component) The same logic that dotnet cake --target=bump-config
would do, but just for these packages. Do this for all com.squareup.okhttp3 libraries.
Co-authored-by: jonathanpeppers <[email protected]>
Bumped nugetVersion by .1 for all com.squareup.okhttp3 packages (logging-interceptor, okhttp, okhttp-android, okhttp-brotli, okhttp-java-net-cookiejar, okhttp-jvm, okhttp-tls, okhttp-urlconnection). All versions updated from 5.1.0 to 5.1.0.1. Commit: 1f006a2
Type forwarding has been implemented with 46 type forwarders from Square.OkHttp3 to Square.OkHttp3.Android. The okhttp-android package already has its own Transforms/Metadata.xml with proper transforms, so the "spin status" should remain consistent. The existing assemblies will maintain backward compatibility through the type forwarders. Commit: 1f006a2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From OkHttp version 5.0.0+, Square changed their packaging strategy to provide separate JVM and Android artifacts. The regular
com.squareup.okhttp3:okhttp
artifact is now just an empty placeholder for Android (containing only 767 bytes of metadata), while the actual Android implementation has been moved tocom.squareup.okhttp3:okhttp-android
.This change caused the generated Square.OkHttp3 NuGet packages version 5.0.0+ to be empty, as they were binding the placeholder JAR instead of the real Android implementation.
However, other packages (like Retrofit 3.0.0) still depend on the legacy
okhttp
artifact, so simply switching artifacts would break dependency resolution.Solution
This PR implements a dual-package approach with full backward compatibility:
Legacy compatibility package:
com.squareup.okhttp3:okhttp:5.1.0
dependencyOnly: true
to satisfy existing dependenciesSquare.OkHttp3
(maintains existing package ID)extraDependencies
to automatically bring inSquare.OkHttp3.Android
New Android implementation package:
com.squareup.okhttp3:okhttp-android:5.1.0
source/com.squareup.okhttp3/okhttp-android/
Square.OkHttp3.Android
(new package ID)Type Forwarders for Seamless Migration
Added comprehensive type forwarding in
TypeForwards.cs
to ensure existing C# code continues working:Changes Made
okhttp
(legacy) andokhttp-android
(new implementation)source/com.squareup.okhttp3/okhttp/Additions/TypeForwards.cs
okhttp:5.1.0
as dependency-only packageextraDependencies
to make Square.OkHttp3 depend on Square.OkHttp3.AndroidThis approach ensures backward compatibility while providing access to the correct OkHttp Android functionality. Retrofit and other packages can still resolve their
okhttp
dependencies, existing code usingSquare.OkHttp3
types continues to work through type forwarders, and consumers automatically get the actual Android implementation.Fixes #1230.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.