0

My react native app is functioning properly on emulator. But after generating apk version of the app, I could not log in to the app on android device.

What could be the possible solutions ? Please !!!

1 Answers1

0

There are two possible situations

1- The API you are hitting is on HTTP you required HTTPS instead you can enable the HTTP support as well check the link for details How to allow all Network connection types HTTP

2- Android is blocking the API request for some reason change the device to test

  • HTTP would be a problem on the emulator as well- the no cleartext restriction also exists on emulators, and in debug mode. More likely he can't access the URL- likely either due to using the hardcoded 10.0.2.2 which won't work on a real device or from not having his router allow network access. I don't know what you mean by "change the device to test", but unless your device is running a proxy that blocks URLs, Android doesn't block API requests. – Gabe Sechan Aug 08 '22 at 06:31
  • FYI, HTTP works in both emulator and android in debug mode but after generating APK( release build), HTTPS is required, if you want to bypass the HTTP then add cleartext. – Ascender Aug 08 '22 at 07:10
  • Changing the device means testing it on another device to verify the issue if something related to the Android OS level – Ascender Aug 08 '22 at 07:13
  • @GabeSechan this is for you https://github.com/facebook/react-native/issues/24408#issuecomment-482123560 – Ascender Aug 08 '22 at 07:17
  • Yes, Android above a certain version blocks HTTP by default. But he says it worked on the emulator. The emulator also blocks HTTP, as the emulator is running the Android OS. So if it worked on the emulator but not a device, that isn't the issue. And no, it doesn't make a difference if the app is a debug release- a debug release's only difference is symbols aren't stripped and the signing key is auto-generated. – Gabe Sechan Aug 08 '22 at 14:44
  • No, that’s not the only difference between debug and release build, when you build in debug mode the debug flag enabled which disable the basic security checks like(https) and enable the profiler, debugger, ... and many more things. – Ascender Aug 08 '22 at 15:11
  • When talking about emulator it's 99% clear he is talking about debug build, but when he generated the apk and run on the real device the login not worked which simply refer to HTTP and HTTPS problem in my view. – Ascender Aug 08 '22 at 15:15
  • You're absolutely wrong. Debug builds also block HTTP. So does the emulator. You can turn that block off and maybe you have, but the default on both is that HTTP and all cleartext is blocked. I know that because I just tried to do it YESTERDAY and had to override in the manifest to allow HTTP. But what is an actual common problem? People using the 10.0.2.2 IP and not changing it when they move to release. Or forgetting that when they move to a real device they need to poke a hole in their firewall to access the server. – Gabe Sechan Aug 08 '22 at 15:30