4

I'm working on a React Native App. I'm using Axios to make api calls to server which is in PHP Laravel. If I run the app with the debug build everything works as expected. I can make calls to server with no problem. When I try the release apk, Axios always gives "Network Error" the status for which is 0. I've confirmed that I don't receive any request on the server aswell. But this only happens in Release apk.

Im using local ip 192.168.0.112 on which the server is running on port 80. I've tried different ports aswell to no avail. The thing is that if I can make calls to server in debug apk then what's the issue with the release apk for instantly giving "Network Error"?

//This is the first call that I make in the first launch of app when user //presses Login button, this is where it fails and the code in catch runs.

Axios.post(server + "app/login", {
    email: user.userEmail.toLowerCase(),
    password: user.userPassword
    })
      .then(function(response) {
        //This part doesn't run in release but works fine in debug
        if (response.data.access_token.length) {
        //Do Stuff If Logged In
        }
    })
      .catch(function(error) {
      //This is always executed in release as soon as the request is made
      //i.e as soon as I press login button to login
      console.log(error.request.status, error.config.url); 
      // Gives status = 0 and url "http://192.168.0.112/app/login"
    });

Expected output should be that the app lets me login for correct credentials and give me the message "Wrong Email or Password" as I've put in for wrong credentials. And I do get this output in Debug perfectly. The error occurs only in Release Apk.

2 Answers 2

7

Do below change in your manifest file

   <manifest xmlns:tools="http://schemas.android.com/tools"> 
        <application android:usesCleartextTraffic="true" tools:targetApi="28"> 
        </application>
     </manifest>
0
4

I found the answer to this problem as indicated here: https://github.com/facebook/react-native/issues/23986#issuecomment-475783025

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.