Development build works great but Preview build won't make requests

circumstances

  • managed workflow
  • VERSION eas-cli/5.4.0 linux-x64 node-v16.18.0
  • SDK 49
  • platform: android

problem

I have this Development build of my super basic app that works as expected.

However, when trying to build with the Preview build profile, whose only difference is developmentClient set to false, the app won’t make any request to my own API, while it would work ok with the 3rd party auth server.

please find below my very simple eas.json file:

{
  "cli": {
    "version": ">= 5.4.0"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "distribution": "internal",
      "android": {
        "buildType": "apk"
      }
    },
    "production": {}
  },
  "submit": {
    "production": {}
  }
}

what have I tried so far

  1. I read the docs :slight_smile: and followed the recommended approach to debugging e.g. running the app with npx expo start --no-dev --minify
  2. checked all the possible server logs (nginx, gunicorn) and I can confirm that:
    • when the app is run via Expo Go or DevBuild all the requests reach the backend server
    • when the app is run as a Preview build, no requests appear in any log file
  3. I excluded that the environment variables had anything to do with this, to the point that I had hardcoded them in the codebase to rule out any importing issues
  4. checked the EAS build logs: the only suspicious thing is Expo Doctor failing (which happens either in Development and Preview builds)
✖ Check that native modules use compatible support package versions for installed Expo SDK
Detailed check results:
Expected package @expo/config-plugins@~7.2.2
Found invalid:
  @expo/config-plugins@6.0.2
  @expo/config-plugins@6.0.2
  (for more info, run: npm why @expo/config-plugins)
Some dependencies are incompatible with the installed expo version:
  expo-auth-session@4.1.0 - expected version: ~5.0.2
Your project may not work correctly until you install the correct versions of the packages.
Fix with: npx expo install --fix
Found outdated dependencies
One or more checks failed, indicating possible issues with the project.
Advice: Upgrade dependencies that are using the invalid package versions.
Advice: Use 'npx expo install --check' to review and upgrade your dependencies.
Command "expo doctor" failed.
 npx -y expo-doctor exited with non-zero code: 1

I know that I am running an outdated expo-auth-session version. This is because upgrading to the latest version would break my app with SDK 49. Still it seems to me that this isn’t the culprit of the malfunctioning as the login/logout logic works with any build.

Being relatively new to Expo I would appreciate any help, thanks :pray:

Hi @alfx

Are you by any chance using HTTP to talk to your API server instead of HTTPS? These days that sort of thing is denied by default unless you configure the app to allow clear text traffic.

For Android you can do it using Build Properties. There’s an “usesCleartextTraffic” option:

See also the example of how to use Build Properties in app.json further up the page.

In iOS this sort of thing needs to be configured in Info.plist. In a managed Expo app you don’t have direct access to Info.plist, but you can also configure that from app.json.

There’s an example here:

But if this is the problem you might also look into getting a free Let’s Encrypt SSL certificate for your API server instead.

Also if you haven’t yet, check out Keith’s video about using the native device logs for debugging production app errors:

1 Like

You are exactly right, I didn’t setup the SSL certificate for the server because I had no idea of production builds refusing to request over HTTP.

Implementing usesCleartextTraffic solves the issue for the time being, but I will proceed to migrate to HTTPS right before releasing the production build.

thanks a lot @wodin !

1 Like

It’s a thing that both Android and iOS did to improve security.

The development builds are configured to allow clear text traffic so that they can connect to the development server over HTTP.

1 Like

BTW
For those who will land here in the future, let me add that this video is super helpful: it explains how to log errors from built apps using Android Studio. But let’s say that you don’t like Android Studio for some reason like being too bloated for you… well, you can filter the logcat output in the same way explained in the video through command line only via adb, using the following command and your app scheme e.g. com.author-name.app-name:

adb logcat -e <your-app-scheme>
1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.