Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Axios Post Works In Debug But Gives "Network Error" In Android Release Build

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.

like image 920
MGB Avatar asked Dec 31 '22 22:12

MGB


1 Answers

Do below change in your manifest file

   <manifest xmlns:tools="http://schemas.android.com/tools"> 
        <application android:usesCleartextTraffic="true" tools:targetApi="28"> 
        </application>
     </manifest>
like image 135
Rajesh Nasit Avatar answered Jan 08 '23 02:01

Rajesh Nasit