0

I am working on a React Native project under a corporate proxy. How can I set it properly so that I can build the application (react-native run-android or Double R for reloading) and having access to internet on the device ?

PS : I'm using Windows and executing my code on a Android Emulator from Android Studio.

I tried multiple things ( https://medium.com/@Charles_Stover/create-a-react-native-app-on-an-android-emulator-1c0d94f288ae, ... ):

Without any configuration, the build works find but using fetch always returns a timeout (and accessing to chrome application, I do not have access to internet).

I configured the proxy in the wifi of the device (Settings > Network & Internet > Wi-Fi > AndroidWifi > Modify Network > Set Proxy)

  • Proxy Manual
  • hostname proxy.company.int
  • port 80
  • bypass proxy for 10.x.y.z, 192.168.x.y, localhost, *.local

I can access to internet (both in the previously built application and with Chrome) but could not either reload the application or rebuild it (a white screen appears).

I tried a lot of different things for no_proxy (based on ipconfig which gave me 2 IPs, one private (10.x.y.z) and one public (192.168.x.y). None of them worked so far.

I also tried to configure the parameters of Android Studio > File > Settings > Appearance & Behaviour > System Settings > HTTP Proxy with the same config, without good results.

I also tried to configure the parameters of the device (not the wifi directly but the options in the toolbar next to the emulated device) : ... > Settings > Proxy > Use Android Studio HTTP proxy settings / no proxy / manual proxy configuration.

Environment :

Windows 10 React-native 0.55.4 Android Studio 2.3.3

Thanks in advance

Iwerzhon
  • 63
  • 1
  • 8
  • Where is your bundle loaded from? Localhost? – JRK Oct 03 '18 at 14:16
  • The source of the project are in a local folder on my windows computer. I execute it with the CLI of React Native `react-native run android` The build folder is located in the same folder `C:\...\project\android.` I also tried to edit the gradle configuration in ./android/gradle.properties by adding `systemProp.http.proxyHost`, `systemProp.http.proxyPort` and the https configuration as well but it didn't work. – Iwerzhon Oct 03 '18 at 14:20
  • I tried this solution : https://stackoverflow.com/questions/36803553/how-do-i-add-http-proxy-to-an-android-emulator-launch-from-android-studio-2-0 and by configuring the proxy I could access to internet again, but got the same error when reloading the application : **Generated by proxy-name ** – Iwerzhon Oct 04 '18 at 13:53

1 Answers1

2

If you build an application with React Native on a simulator under a corporate proxy, make sure to :

  • Configure your proxy in Android Studio by setting the IP 10.0.2.2 (or any IP that is shown when trying to rebuild the application) in NO_PROXY : Android Studio config
  • Access to the emulator config and make sure you use the configuration of Android Studio. You don't need to update the configuration inside the device (but it works if you want to set it only for one device) : Android Emulator Settings

  • Restart the emulator (just in case) and that's it

Iwerzhon
  • 63
  • 1
  • 8
  • I also have to disable the proxy setting from inside de the emulator. The one in wifi -> Android Wifi -> Advanced options -> Proxy = None – gexhange May 25 '21 at 20:20