Repository navigation
Conversation
ide
marked this pull request as ready for review
November 29, 2026 10:48
ide
force-pushed
the
feature/okhttp5-compat
branch
from
December 1, 2026 00:13
0948886 to
4538fa6
Compare
cortinico
requested changes
Dec 2, 2026
| api(libs.yoga.proguard.annotations) | ||
|
|
||
| api(libs.jsr305) | ||
| api(libs.okhttp3.urlconnection) |
Contributor
There was a problem hiding this comment.
I believe this can be made non-breaking as apps can declare in their .gradle files that they don't intend to consume this api dependency from react-native.
Contributor
Author
There was a problem hiding this comment.
ReactAndroid now keeps okhttp-urlconnection as an api dependency, so the change is no longer breaking, and the [BREAKING] changelog entry is gone.
An app on OkHttp 5 needs to exclude it only if its code or a keep rule retains JavaNetCookieJar.
ide
force-pushed
the
feature/okhttp5-compat
branch
2 times, most recently
from
December 2, 2026 15:40
f378dfa to
13c1611
Compare
cortinico
approved these changes
Dec 2, 2026
ide
force-pushed
the
feature/okhttp5-compat
branch
from
December 3, 2026 03:07
13c1611 to
3e99c93
Compare
An app that depends on OkHttp 5 crashes when React Native loads cookies (react#52945). Gradle resolves okhttp to the app's 5.x, but okhttp-urlconnection stays at the 4.9.2 that ReactAndroid declares, and its JavaNetCookieJar calls okhttp3.internal.Util, which OkHttp 5 removed. No okhttp-urlconnection release works with OkHttp 3, 4 and 5, because each calls internals of its own major version. Add CookieHandlerCookieJar, a port of OkHttp 5's JavaNetCookieJar onto API that OkHttp 3, 4 and 5 share, and use it in NetworkingModule and FrescoModule. React Native no longer uses okhttp-urlconnection. ReactAndroid still declares it as an api dependency, so code that uses JavaNetCookieJar or JavaNetAuthenticator through React Native keeps compiling, and the tests use it to compare the port with JavaNetCookieJar from the OkHttp version under test. An app on OkHttp 5 needs no change unless its code or a keep rule retains JavaNetCookieJar: R8's shrinking removes the unused 4.9.2 classes, so a minified build doesn't fail on the OkHttp 4 internals they call. An app that uses JavaNetCookieJar on OkHttp 5 declares okhttp-urlconnection at its OkHttp version, and an app that wants the dependency gone can exclude it from react-android and any other dependency that brings it in. Like OkHttp 5.5.1's, the port accepts a value that is a lone quote and a value with whitespace just inside its quotes; earlier versions throw on both. Unlike JavaNetCookieJar, it logs and skips a cookie that Cookie.Builder rejects, such as one whose name starts with a vertical tab. Uncaught, that exception fails the request, and OkHttp rethrows it on its dispatcher thread, which crashes the app. Two other things differ on OkHttp 5: - Response.body() is non-null, so seven null checks that OkHttp 3 and 4 need become warnings, which -PenableWarningsAsErrors=true makes errors. Each check now reads the body into an explicitly nullable value first. - MultipartBody reports itself as one-shot when any part is, so getRequestBodyPreview showed a form upload with a file as only "[Binary data, N bytes]" in DevTools. It now checks the parts first. Run the OkHttp compatibility job as a matrix over OkHttp 3.14.9 and 5.5.1, with warnings as errors. The init script takes the version as -PokhttpCompatVersion and logs the Okio version it resolves. Add the OkHttp 5 rules to AGENTS.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ide
force-pushed
the
feature/okhttp5-compat
branch
from
December 3, 2026 03:35
3e99c93 to
ca8d6fc
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
This makes OkHttp 5 usable in React Native apps on Android. Today an app that depends on OkHttp 5 crashes when React Native loads cookies (#52945):
okhttp-urlconnectionstays at 4.9.2, and itsJavaNetCookieJarcalls an OkHttp internal that 5 removed.With this change, an app opts in by depending on OkHttp 5:
Apps whose dependencies don't select OkHttp 5 keep OkHttp 4.9.2, and React Native stays source-compatible with OkHttp 3.14.9.
CookieHandlerCookieJarreplacesJavaNetCookieJarand uses only API that OkHttp 3, 4 and 5 share. React Native no longer usesokhttp-urlconnection, but ReactAndroid still declares it, so code that usesJavaNetCookieJarorJavaNetAuthenticatorthrough React Native keeps compiling. An app on OkHttp 5 needs no change unless its code or a keep rule retainsJavaNetCookieJar: R8's shrinking removes the unused 4.9.2 classes, so a minified build doesn't fail on the OkHttp 4 internals they call. An app that usesJavaNetCookieJaron OkHttp 5 declaresokhttp-urlconnectionat its OkHttp version. An app that wants the dependency gone can exclude it from itsreact-androiddependency, and from any other dependency that brings it in:DevTools previews multipart uploads part by part on OkHttp 5 too, whose
MultipartBodyreports itself as one-shot when any part is.Response.body()null checks no longer warn on OkHttp 5, where the body is non-null.The
test_okhttpCI job intest-android.yml, from Add OkHttp 3 compatibility CI for ReactAndroid #60342, runs against OkHttp 3.14.9 and 5.5.1.Changelog:
[ANDROID] [FIXED] - Fix a crash loading cookies in apps that depend on OkHttp 5
Test Plan:
./gradlew --init-script .github/workflow-scripts/okhttp-compat.gradle -PokhttpCompatVersion=5.5.1 -PenableWarningsAsErrors=true :packages:react-native:ReactAndroid:verifyOkHttpCompatibilitypasses, and so does the same command with3.14.9../gradlew -PenableWarningsAsErrors=true :packages:react-native:ReactAndroid:testDebugUnitTestpasses on the catalog's 4.9.2.CookieHandlerCookieJarTestchecks the port againstJavaNetCookieJarfrom the OkHttp version under test.okhttp5.5.1 andokhttp-urlconnection4.9.2,JavaNetCookieJar.loadForRequestthrowsNoClassDefFoundError: okhttp3/internal/Util, and the port works.okhttp-android5.5.1 and Okio 3.18.1 withokhttp-urlconnection4.9.2 among its inputs. When the app keepsJavaNetCookieJar, R8 fails withMissing class okhttp3.internal.Util.Not run: an app on a device with OkHttp 5, and Meta's internal build with OkHttp 3.