My code is not hitting the server url

My code is working perfectly when i am serving the app. It works perfectly also in my mobile browser but when i build an apk it is showing no compile time errors but the server url is not hitting. I have declared my url in environment.ts file. Also if there any additional changes do let me know!!

I am new to ionic so plz help me.

change this in config.xml

  1. <widget id="com.illuminatus.qna" version="0.0.2" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    
  2. <preference name="android-minSdkVersion" value="19" />         <preference name="android-targetSdkVersion" value="28" /> 
    
  3.    <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
         <application android:usesCleartextTraffic="true" />
         <application android:allowBackup="false" />
         <application android:fullBackupOnly="false" />
     </edit-config>  
    

then remove platform and re add platform
i) ionic cordova platform remove android
ii) ionic cordova platform add android

test it this should work

Thanks for your reply.
But i feel like i have my error in HttpHeaders.

Can you pls suggest me that

I had faced same issue my app was working on browser but not on android so i searched for it and found this solution and i tried it its working for me please try once

I Tried it… It is not working…

ionic cordova platform add android then run
ionic cordova run android and test on emulator or device using app-debug.apk

Please post textual information as text.

i added my platform and tested my app on the browser and its running but when i m testing it on my device using ionic cordova run android command (i also generated an apk file and its running ),its getting installed and running too but when i am trying to login with credentials in my app and hit login button , its displaying an ERROR[object,progress event]! I am sharing auth.service.ts code snippet below.

login(credentials) {
console.log(this.url);
let header: HttpHeaders = new HttpHeaders();
header = header.append(‘Content-Type’, ‘application/json’);
return this.http.post(${this.url}/users/login, credentials, { headers : header } )
.pipe(
tap(res => {
this.storage.set(TOKEN_KEY, res[‘token’]);
console.log(res[‘token’]);
console.log(TOKEN_KEY);
this.user = this.helper.decodeToken(res[‘token’]);
this.storage.set(‘userid’, res[‘id’] );
console.log(“Hi”+ res[‘id’]);
this.TOKENKEY = res[‘token’];
this.userid = res[‘id’];
this.storage.set(‘userid’, this.userid);
console.log(this.userid);
this.authenticationState.next(true);
this.authenticationState.subscribe(state => {
if (state) {
this.router.navigate([‘tabs’]);
} else {
this.router.navigate([‘login’]);
}
});
}),
catchError(e => {
console.log(e.error);
this.showAlert(“Error” + e.error.msg + e.error );
throw new Error(e);
})
);
}

I guess my login method is not being accessed and the error is being displayed after hitting login button!
My code is working perfectly fine when i am serving it but after building it in my device i am getting an error as i said earlier! My server url is not being hit and maybe thats why i am getting an error! Also do let me know if there is any issues with HTTP header .
Thank you

My code is now working
My config.xml file looks like this ->

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">

            <application android:usesCleartextTraffic="true" />

        </edit-config>

After That : ionic cordova platform rm android
ionic cordova platform add android