callstack / repack

A Webpack-based toolkit to build your React Native application with full support of Webpack ecosystem.
https://re-pack.dev
MIT License
1.45k stars 104 forks source link

[Android][Hermes] NativePack's OKHttp3 Version Causes Runtime Error Making HTTP Calls to LocalHost #40

Closed chevonc closed 3 years ago

chevonc commented 3 years ago

Environment

react-native: 0.64.0 nativepack: 1.4.2 android studio 4.1

Description

nativepack Okhttp3 version causes runtime errors

Debugging android using emulator throws JSC and OKHttp Error when making API http network call to localhost

Documentation and default example doesn't include appropriate to configure right build configuration for apps that make api network calls

Reproducible Demo

Setup restify or express node api server and attempt to make an API network call to the node server using react-native fetch APIs

Errors

java.lang.NoSuchMethodError: No virtual method toString(Z)Ljava/lang/String; in class Lokhttp3/Cookie; or its super classes (declaration of 'okhttp3.Cookie'

image

Work Around

Force same version as react-native 0.64.0 in app's app/build.gradle and include default JS in debug build

image

This is not documented, and I'm not sure of the consequnces

zamotany commented 3 years ago

I don't that the problem is with making requests to localhost - the TesterApp and my other project with Nativepack are working perfectly fine with localhost. Based on the error message is has more to do with cookies.

chevonc commented 3 years ago

Yes, the problem is specifically related to cookie parsing during the XHR lifecycle. The end result though, is it's local request don't work. Cookies are pretty standard, so I'm kind of surprised the example app works.

In either case, the selected version is causing an issue parsing the cookie header + deviates from what RN has selected, so it'll end up upgrading the target app's OKHTTP version silently, which then fail is random at runtime. If we could lock the version or update the documentation, I think that'd help reduce the integration issues

zamotany commented 3 years ago

I think the best solution is to use the same version as React Native.

chevonc commented 3 years ago

I agree. What I'm suggestion here is if we could document this in the setup guide. It'll save a lot of other users time. See my diff above for the required changes

zamotany commented 3 years ago

I'm going to close this issue - I've open a PR #75 to address this problem. Adding okhttp-urlconnection:4.9.0 solves the problem and starting from 0.65, React Native uses 4.9.1 of OkHttp. I've added a note about potential incompatibilities of OkHttp versions in #44