Skip to content

Commit 9994658

Browse files
Fix missing code in Square.OkHttp3 5.0.0+ (#1239)
Fixes: #1230 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 with full backward compatibility: 1. **Legacy compatibility package**: `com.squareup.okhttp3:okhttp:5.1.0` - Marked as `dependencyOnly: true` to satisfy existing dependencies - Contains **type forwarders** for all 50 public types to Square.OkHttp3.Android - NuGet package: `Square.OkHttp3` (maintains existing package ID) - Includes `extraDependencies` to automatically bring in `Square.OkHttp3.Android` 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) ## Type Forwarders for Seamless Migration Added comprehensive type forwarding in `TypeForwards.cs` to ensure existing C# code continues working: ```csharp [assembly:TypeForwardedToAttribute(typeof(Square.OkHttp3.OkHttpClient))] [assembly:TypeForwardedToAttribute(typeof(Square.OkHttp3.Request))] [assembly:TypeForwardedToAttribute(typeof(Square.OkHttp3.Response))] // ... and 47 more types ``` ## Changes Made - **config.json**: Added separate entries for both `okhttp` (legacy) and `okhttp-android` (new implementation) - **Version bumping**: All com.squareup.okhttp3 packages updated to 5.1.0.1 (revision bump) - **Source structure**: Created `source/com.squareup.okhttp3/okhttp/Additions/TypeForwards.cs` - **Dependency resolution**: Fixed dependency resolution errors by adding `okhttp:5.1.0` as dependency-only package - **NuGet dependencies**: Added `extraDependencies` to make Square.OkHttp3 depend on Square.OkHttp3.Android This 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 using `Square.OkHttp3` types continues to work through type forwarders, and consumers automatically get the actual Android implementation. Co-authored-by: Jonathan Peppers <[email protected]>
1 parent 22c5903 commit 9994658

File tree

6 files changed

+945
-8
lines changed

6 files changed

+945
-8
lines changed

config.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4293,7 +4293,7 @@
42934293
"groupId": "com.squareup.okhttp3",
42944294
"artifactId": "logging-interceptor",
42954295
"version": "5.1.0",
4296-
"nugetVersion": "5.1.0",
4296+
"nugetVersion": "5.1.0.1",
42974297
"nugetId": "Square.OkHttp3.LoggingInterceptor",
42984298
"type": "androidlibrary",
42994299
"mavenRepositoryType": "MavenCentral"
@@ -4302,16 +4302,26 @@
43024302
"groupId": "com.squareup.okhttp3",
43034303
"artifactId": "okhttp",
43044304
"version": "5.1.0",
4305-
"nugetVersion": "5.1.0",
4305+
"nugetVersion": "5.1.0.1",
43064306
"nugetId": "Square.OkHttp3",
4307+
"extraDependencies": "com.squareup.okhttp3.okhttp-android",
4308+
"type": "androidlibrary",
4309+
"mavenRepositoryType": "MavenCentral"
4310+
},
4311+
{
4312+
"groupId": "com.squareup.okhttp3",
4313+
"artifactId": "okhttp-android",
4314+
"version": "5.1.0",
4315+
"nugetVersion": "5.1.0.1",
4316+
"nugetId": "Square.OkHttp3.Android",
43074317
"type": "androidlibrary",
43084318
"mavenRepositoryType": "MavenCentral"
43094319
},
43104320
{
43114321
"groupId": "com.squareup.okhttp3",
43124322
"artifactId": "okhttp-brotli",
43134323
"version": "5.1.0",
4314-
"nugetVersion": "5.1.0",
4324+
"nugetVersion": "5.1.0.1",
43154325
"nugetId": "Square.OkHttp3.OkHttp.Brotli",
43164326
"type": "androidlibrary",
43174327
"mavenRepositoryType": "MavenCentral"
@@ -4320,7 +4330,7 @@
43204330
"groupId": "com.squareup.okhttp3",
43214331
"artifactId": "okhttp-java-net-cookiejar",
43224332
"version": "5.1.0",
4323-
"nugetVersion": "5.1.0",
4333+
"nugetVersion": "5.1.0.1",
43244334
"nugetId": "Square.OkHttp3.JavaNetCookieJar",
43254335
"type": "androidlibrary",
43264336
"mavenRepositoryType": "MavenCentral"
@@ -4329,7 +4339,7 @@
43294339
"groupId": "com.squareup.okhttp3",
43304340
"artifactId": "okhttp-jvm",
43314341
"version": "5.1.0",
4332-
"nugetVersion": "5.1.0",
4342+
"nugetVersion": "5.1.0.1",
43334343
"nugetId": "Square.OkHttp3.JVM",
43344344
"type": "androidlibrary",
43354345
"mavenRepositoryType": "MavenCentral"
@@ -4338,7 +4348,7 @@
43384348
"groupId": "com.squareup.okhttp3",
43394349
"artifactId": "okhttp-tls",
43404350
"version": "5.1.0",
4341-
"nugetVersion": "5.1.0",
4351+
"nugetVersion": "5.1.0.1",
43424352
"nugetId": "Square.OkHttp3.OkHttp.TLS",
43434353
"type": "androidlibrary",
43444354
"mavenRepositoryType": "MavenCentral"
@@ -4347,7 +4357,7 @@
43474357
"groupId": "com.squareup.okhttp3",
43484358
"artifactId": "okhttp-urlconnection",
43494359
"version": "5.1.0",
4350-
"nugetVersion": "5.1.0",
4360+
"nugetVersion": "5.1.0.1",
43514361
"nugetId": "Square.OkHttp3.UrlConnection",
43524362
"type": "androidlibrary",
43534363
"mavenRepositoryType": "MavenCentral"

0 commit comments

Comments
 (0)