Skip to content

Fix Square.OkHttp3 5.0.0+ by creating separate okhttp-android package while maintaining legacy 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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 4, 2025

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 to com.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:

  1. Legacy compatibility package: com.squareup.okhttp3:okhttp:4.12.0

    • Marked as dependencyOnly: true to satisfy existing dependencies
    • No binding customizations (empty placeholder)
    • NuGet package: Square.OkHttp3 (maintains existing package ID)
  2. New Android implementation package: com.squareup.okhttp3:okhttp-android:5.1.0

    • Contains the actual 839KB Android implementation
    • All existing binding customizations moved to source/com.squareup.okhttp3/okhttp-android/
    • NuGet package: Square.OkHttp3.Android (new package ID)

Changes Made

  • config.json: Added separate entries for both okhttp (legacy) and okhttp-android (new implementation)
  • Source structure: Created source/com.squareup.okhttp3/okhttp-android/ with existing Metadata.xml and customizations
  • Dependency resolution: Retrofit and other packages can still resolve their okhttp dependencies while new consumers get the full Android implementation

This approach ensures backward compatibility while providing access to the correct OkHttp Android functionality.

Fixes #1230.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] "Square.OkHttp3" 5.0.0+ is broken Fix Square.OkHttp3 5.0.0+ broken bindings by switching to okhttp-android artifact Aug 4, 2025
Copilot finished work on behalf of mattleibow August 4, 2025 17:05
@Copilot Copilot AI requested a review from mattleibow August 4, 2025 17:05
Copy link
Member

@jonathanpeppers jonathanpeppers left a 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
		   }

config.json Outdated
Comment on lines 4301 to 4303
{
"groupId": "com.squareup.okhttp3",
"artifactId": "okhttp",
"artifactId": "okhttp-android",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this a new package, and move the relevant Metadata.xml and Additions/*.cs to be used in the new package?

Keep the existing okhttp package, and it shouldn't need Metadata.xml or Additions/*.cs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Created a new package approach:

  • okhttp (4.12.0): Kept for dependencies, removed customizations, marked as dependencyOnly: true
  • okhttp-android (5.1.0): New package Square.OkHttp3.Android with all existing Metadata.xml and binding customizations moved to source/com.squareup.okhttp3/okhttp-android/

This maintains compatibility with existing consumers while providing the correct Android implementation. Commit: dc5482d

Copy link
Contributor Author

Copilot AI commented Aug 4, 2025

There are lots of errors:


...

Fixed the dependency resolution error by creating separate packages:

  1. Added com.squareup.okhttp3:okhttp:4.12.0 with dependencyOnly: true to satisfy Retrofit 3.0.0 dependencies
  2. Created new com.squareup.okhttp3:okhttp-android:5.1.0 package (Square.OkHttp3.Android) for actual Android functionality
  3. Moved binding customizations from okhttp to okhttp-android directory

This ensures all dependencies resolve while providing the correct Android implementation in a separate NuGet package. Commit: dc5482d

@Copilot Copilot AI changed the title Fix Square.OkHttp3 5.0.0+ broken bindings by switching to okhttp-android artifact Fix Square.OkHttp3 5.0.0+ by creating separate okhttp-android package while maintaining legacy compatibility Aug 4, 2025
@Copilot Copilot AI requested a review from jonathanpeppers August 4, 2025 20:06
Copilot finished work on behalf of jonathanpeppers August 4, 2025 20:06
config.json Outdated
Comment on lines 4304 to 4305
"version": "4.12.0",
"nugetVersion": "4.12.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot shouldn't this be 5.1.0 version? You are downgrading this package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right! Updated the okhttp version from 4.12.0 to 5.1.0 to match the okhttp-android version. Both packages now use version 5.1.0 consistently. Commit: 986e6a4

@Copilot Copilot AI requested a review from jonathanpeppers August 4, 2025 21:02
Copilot finished work on behalf of jonathanpeppers August 4, 2025 21:02
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.

"Square.OkHttp3" 5.0.0+ is broken
3 participants