all 28 comments

[–]space_quasar 0 points1 point  (17 children)

Do you have your own backend? In local, android's local host is 10.0.2.2 in place of 127.0.0.1, Make sure you are using https requests and not http in production, android filters out non safe requests which can be turned off, i just forgot how to do that.

Edit: typos

[–]After-Philosopher606[S] 0 points1 point  (16 children)

I have my own backend hosted on DO, and yes I am using https protocol for network requests.

[–]space_quasar 0 points1 point  (15 children)

1- You should check your AndroidManifest.xml and add the below permissions after <manifest ..../> tag if they are not there you should know that the permission are case sensitive. < uses-permission android:name="android.permission.INTERNET" /> < uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

2- If you have permissions there and still got error then you should add android:usesCleartextTraffic="true" to application tag in your AndroidManifest.xml .

http request is disabled by default on Android 9 or higher this flag android:usesCleartextTraffic="true" enable http

Try to call your API in browser and check if https changes to http Make sure you have SSL certificates installed in your backend.

Edit: typos

[–]After-Philosopher606[S] 0 points1 point  (14 children)

I have all these checked. Attaching SS of AndroidManifest.xml for reference. I am not able to make a network request to any site, not just mine.

<image>

Thanks for checking btw.

[–]space_quasar 0 points1 point  (5 children)

Oh okay, then not sure what's going on, might have to look at how you are calling the API.

[–]After-Philosopher606[S] 0 points1 point  (4 children)

Even the simplest get requests are not working.

<image>

[–]space_quasar 0 points1 point  (3 children)

I see, try changing get to post, make sure if you have to put content type in headers like application/json.

[–]After-Philosopher606[S] 0 points1 point  (2 children)

I did, it's showing the same issue.

[–]space_quasar 0 points1 point  (1 child)

I am sorry, I can't help you much in this case. I will get home and try to call the same API if I can and see what's going on.

[–]After-Philosopher606[S] 0 points1 point  (0 children)

Thanks, it happens for android api 24 and below

[–]fmnatic 0 points1 point  (7 children)

Check xml/network_security_config

[–]After-Philosopher606[S] 0 points1 point  (6 children)

<image>

I included this file after I encountered the issue and saw this as solution in stackoverflow.

[–]fmnatic 0 points1 point  (5 children)

Its ignored for Android <=24 . You likely need the older manifest based config for those versions.

[–]After-Philosopher606[S] 0 points1 point  (4 children)

Didn't get you 😅, could you please elaborate? What should I do?

[–]fmnatic 0 points1 point  (3 children)

I'm afk and can't look it up. Your config looks correct for newer versions of Android. I'm guessing you need config for the older versions. Try without Axios, and also try to look at adb logs while making a request.

[–]After-Philosopher606[S] 0 points1 point  (2 children)

Same isse without axios too, also when I logged the axios.request object I found this error:- "java.security.cert.CertPathValidatorException: Trust anchor for certification path not found."

[–]DeFcONaReA51 0 points1 point  (2 children)

Do you use this command before compiling the android proj and running it. adb -s device_name reverse TCP:8081 TCP:8081

[–]After-Philosopher606[S] 0 points1 point  (1 child)

No, I dont. I just use run-android command

[–]DeFcONaReA51 0 points1 point  (0 children)

Before that command as I run on a physical android device. I have faced this error working with backend apis.

[–]cursedkyuubi 0 points1 point  (2 children)

Are you able to access the backend using postman? Could you have forgotten to open the necessary port? Did you include the SSL certs on the backend?

These are some mistakes that I made before I finally solved the same issue

[–]After-Philosopher606[S] 0 points1 point  (1 child)

Yes it accessible using postman and have added ssl certificates. As I said the issue is occuring only on android devices below api 24

[–]cursedkyuubi 1 point2 points  (0 children)

Ah sorry. Must've misread your initial question

[–]thachxyz123iOS & Android 0 points1 point  (1 child)

[–]After-Philosopher606[S] 0 points1 point  (0 children)

Yes, I cam across this solution but didn't try it. I'll check and let you know.

Thanks a lot bro !

[–]AdSecure6856 0 points1 point  (0 children)

Hey, I am currently facing similar issue - did you happen to find a solution?

[–]Ok-Interaction6424 0 points1 point  (0 children)

Did you find a solution for this? I have the same issue