Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable HTTP requests using Expo?

While I'm in the development environment, I have no issues with HTTP calls. However, after my project is built and uploaded for internal testing via Google Play Console, and I install the store's APK, HTTP requests are not allowed. With React Native without Expo, I know I can adjust this using:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

But I don't know how to do this with Expo without having to create and generate the iOS and Android folders.

I created a network_security_config.xml file and added it to the app.json like this:

"expo": {
  ...
  "android": {
    "config": {
      "networkSecurityConfig": "./network_security_config.xml"
    },
  ...
  }
}

But it didn't work because the networkSecurityConfig field does not exist.

I am using React Native 0.72.4 and Expo 49.0.0

like image 728
Joao-gabriel Avatar asked Oct 24 '25 06:10

Joao-gabriel


1 Answers

hope im not too late, if you're building your application with expo eas, you can still enable CleartextTraffic from your app.config.js or app.json with the expo-build-properties

npx expo install expo-build-properties

inside your app.config.js in plugins should be

    {  
      expo: {
        ..... 
        ...

        ios: {....},
        andriod: {...},

        plugins:[
          [
            'expo-build-properties',
            {
              android: {
                usesCleartextTraffic: true, // ? enable HTTP requests
              },
              ios: {
                flipper: true,
              },
            },
          ],
        ]
      }
    }

for ios is

    {  
      expo: {
        ..... 
        ...

        ios: {
          infoPlist: {
            NSAppTransportSecurity: { NSAllowsArbitraryLoads: true }, // ? enable HTTP requests
          },
          supportsTablet: true,
         },

         andriod: {...},
         plugins:[...]
      }
    }
like image 97
Pedro Bueno Avatar answered Oct 27 '25 03:10

Pedro Bueno