Home > Blockchain >  Cant get REST API requests to work on deployment device with react native
Cant get REST API requests to work on deployment device with react native

Time:03-13

On my emulator I can use get/post requests and everything work fine. but when I deploy it and try on my android phone - seems like nothing happens.

My manifest contains:

<uses-permission android:name="android.permission.INTERNET" />
..
 <application..
android:networkSecurityConfig="@xml/network_security_config"
>
<uses-library android:name="org.apache.http.legacy" android:required="false"/>

the xml file under res folder:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>

    <domain-config cleartextTrafficPermitted="true">

        <!-- For React Native Hot-reloading system -->
        <!-- If you are running on a device insert your computer IP -->
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">mydomain.herokuapp.com</domain>

        <trust-anchors>
            <certificates src="system" />
            <certificates src="user" />
        </trust-anchors>

    </domain-config>

    <base-config cleartextTrafficPermitted="false" />

</network-security-config>

I looked everywhere but cant get it worked.

I have to mention that before trying to make the login authentication I did apply post/get calls and they worked fine. but theres something with the login. it is working on my emulator.

Please if you have any clue or can assist it would be life saving!

(I have white list all IP's in mongodb so theres no problem there).

*I tried with Axios and other request methods non of them worked on the device.

is it because Im trying to run the app-debug.apk? or it has nothing to that

what am I missing?

CodePudding user response:

I think you have built your apk in debug mode. Try build it in release mode.

How to Generate a React Native Release Build APK for Android

  • Related