From 458225029869b6375c4adedfb0aa0b290a74539c Mon Sep 17 00:00:00 2001 From: James Ide Date: Thu, 3 Dec 2026 00:26:18 -0800 Subject: [PATCH] docs: document using OkHttp 5 on Android Why === react/react-native#60385 lets Android apps use OkHttp 5, starting with React Native 0.89. The Networking page doesn't say how to opt in, or what to do about the OkHttp 4 version of `okhttp-urlconnection` that `react-android` brings in. How === Adds a "Using OkHttp 5 on Android" section to the Networking page, before "Configuring NSURLSession on iOS". It shows how to add OkHttp 5, when to also add `okhttp-urlconnection` at the same version, and how to exclude the OkHttp 4 `okhttp-urlconnection` from `react-android`. Test Plan ========= `npx prettier --check docs/network.md` and `npx eslint docs/network.md` pass. Signed-off-by: James Ide --- docs/network.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/network.md b/docs/network.md index 3c1b23a81e9..497a8ca1a53 100644 --- a/docs/network.md +++ b/docs/network.md @@ -259,6 +259,37 @@ The following options are currently not working with `fetch` * Cookie based authentication is currently unstable. You can view some of the issues raised here: https://github.com/react/react-native/issues/23185 * As a minimum on iOS, when redirected through a `302`, if a `Set-Cookie` header is present, the cookie is not set properly. Since the redirect cannot be handled manually this might cause a scenario where infinite requests occur if the redirect is the result of an expired session. +## Using OkHttp 5 on Android + +Starting with React Native 0.89, you can use OkHttp 5 in your Android app by adding it to `android/app/build.gradle`: + +```groovy +// android/app/build.gradle +dependencies { + implementation("com.squareup.okhttp3:okhttp:5.5.1") +} +``` + +If your app or one of its libraries uses `JavaNetCookieJar` or `JavaNetAuthenticator`, you will also need to add `okhttp-urlconnection` at the same version: + +```groovy +// android/app/build.gradle +dependencies { + implementation("com.squareup.okhttp3:okhttp-urlconnection:5.5.1") +} +``` + +`react-android` depends on the OkHttp 4 version of `okhttp-urlconnection`, which React Native does not use and which does not work with OkHttp 5. If you want to remove it from your app, you can exclude it from `react-android` and from any other dependency that brings it in: + +```groovy +// android/app/build.gradle +dependencies { + implementation("com.facebook.react:react-android") { + exclude group: "com.squareup.okhttp3", module: "okhttp-urlconnection" + } +} +``` + ## Configuring NSURLSession on iOS For some applications it may be appropriate to provide a custom `NSURLSessionConfiguration` for the underlying `NSURLSession` that is used for network requests in a React Native application running on iOS. For instance, one may need to set a custom user agent string for all network requests coming from the app or supply `NSURLSession` with an ephemeral `NSURLSessionConfiguration`. The function `RCTSetCustomNSURLSessionConfigurationProvider` allows for such customization. Remember to add the following import to the file in which `RCTSetCustomNSURLSessionConfigurationProvider` will be called: