1

I have built an Android application using Expo v52 with React Native and now I want to generate a preview APK. In my project, I use an environment variable like: EXPO_PUBLIC_API_URL=http://192.168.57.53:3000/api . I want to include this in the APK such that I can update it later without rebuilding the entire app. Is there a way to change it post-build in a preview APK for local testing? like there is option in react website deployment, we set key.

Currently, I have defined EXPO_PUBLIC_API_URL in the .env file, but I read that it can also be specified in eas.json. Is there a way to use EAS secrets to make this variable dynamic?

I haven't built any APK for React Native Expo yet, so please help. I couldn’t find any relevant documentation on this.

2 Answers 2

0

If you want to use environment variables inside your eas.json file, you will need to add env objects inside development, preview & production. This is my eas.json for example.

{
  ...
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal",
      "ios": {
        "simulator": true
      },
      "env": {
        "API_URL": "https://www.google.com/"
      },
      ...
    },
    "preview": {
      "distribution": "internal",
      "ios": {
        "simulator": true
      },
      "android": {
        "buildType": "apk"
      },
      "env": {
        "API_URL": "https://www.facebook.com/"
      },
      ...
    },
    "production": {
      "env": {
        "API_URL": "https://www.stackoverflow.com/"
      }
      ...
    }
  },
  "submit": {
    "production": {}
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Is it possible to make the API_URL dynamic here by storing it in EAS Secrets? I want to update it without needing to rebuild the app.
I doubt it. That i do not know.
0

No, you can't change the value of EXPO_PUBLIC_API_URL after building the APK, because Expo embeds the .env values at build time. To change it post-build, you need to rebuild the APK with new .env values.

1 Comment

Is there another way to make it dynamic?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.