Open lukasver opened 1 year ago
After further investigation, it seems that this forum thread talked about the same issue. Apparently there seems to be a 🐞 in some point of the eas build
process that mess up the env vars.
Update: on further debugging in my app i have .env
, .env.local
, .env.production
set of env vars. When trying to build app with APP_VARIANT=production eas build -p ios --profile production
at some point in the whole building process the .env.production
file is not picked up and everything gets messed up. Eventually app.config
seems to be picking the wrong APP_VARIANT and passing its values to fastlane, ergo I get the error because bundleIdentifiers get mixed up.
A way to reproduce this is to completely remove the .env
file (which in my case has stage vars) and rename .env.production
to .env
and build goes throw successfully.
@lukasver - EAS Build does not use .env.test, .env.development, or .env.production - it will load your env from the "env"
configuration on your build profile
notice when you run eas build
it outputs what env variables are loaded:
Loaded "env" configuration for the "production" profile: SENTRY_ORG, SENTRY_PROJECT, EXPO_PUBLIC_VEXO_API_KEY, EXPO_PUBLIC_SENTRY_DSN, RELEASE. Learn more: https://docs.expo.dev/build-reference/variables/
and when you run npx expo start
it does a similar thing:
env: load .env.development
env: export ABC
I am also seeing this issue, here is a link to my latest build.
This issue keeps happening.
After some time debugging and submitting a clean project to EAS servers to generate a CLEAN build (discard issues related to my xcode config), this generated a build with the wrong dynamic config from app.config.ts
.
This is the build link https://expo.dev/accounts/smatsa/projects/wealth-managers-lite-app/builds/07a1ea4d-1350-4286-8dbb-ebd15ca13aec
and here is a short example of my app.config.ts
:
const IS_DEV =
process.env.APP_VARIANT === 'development' ||
process.env.EXPO_PUBLIC_APP_VARIANT === 'development' ||
process.env.NODE_ENV !== 'production';
const PRODUCTION_CONFIG = {
expo: {
name: process.env.APP_NAME,
slug: 'some-slug',
privacy: 'public',
version: process.env.APP_VERSION || '1.0.0',
orientation: 'portrait',
icon: process.env.APP_ICON ?? './assets/Isologo-wt-bg.png',
}
};
const DEV_CONFIG = {
expo: {
name: process.env.APP_NAME,
slug: 'some-slug',
privacy: 'unlisted',
version: process.env.APP_VERSION || '1.0.0',
orientation: 'portrait',
icon: process.env.APP_ICON ?? './assets/logo-stage.png',
}
};
const config = IS_DEV ? DEV_CONFIG : PRODUCTION_CONFIG;
export default () => {
return {
...config
};
};
by running the following command to build:
APP_VARIANT=production eas build -p ios --profile production
I noticed that the app is using the correct set of envs from the profile production
but at some point in the building process the DEV config is picked up from the app.config.ts
instead resulting in a build with wrong config (stage logos and assets for exmple).
My guess some sub shell running with NODE_ENV !== production
?
I am also experiencing this issue.
Through a bunch of testing various build configurations, I've been able to confirm that at some point in the build process, the environment variable defined in eas.json
is getting overridden by a value set in .env.development
.
This causes dynamic properties in app.config.ts
set with environment variables to have the incorrect value during certain steps of the build process.
For us, this arises in the "Fastlane" build step for iOS.
We dynamically set the bundle identifier in app.config.ts
like so:
ios: {
bundleIdentifier: `com.ourorg.ourapp.${ENVIRONMENT}`
}
We set up the build config in eas.json, to include:
"build": {
"development": {
"developmentClient": true,
"distribution": "internal",
"env": {
"ENVIRONMENT": "in-development-profile",
}
"staging": {
"channel": "staging",
"distribution": "internal",
"env": {
"ENVIRONMENT": "in-staging-profile"
}
},
And have a .env.development
with:
ENVIRONMENT=in-development-env
And then run eas build --profile staging --platform ios
The outcome is the "Spin up build environment" build step will show the correct value:
Project environment variables:
ENVIRONMENT=in-staging-profile
And the "Read app config" step shows the correct dynamic value:
"ios": {
"bundleIdentifier": "com.ourorg.ourapp.in-staging-profile"
},
But the "Run Fastlane" step fails with this error:
There seems to be a mismatch between your provided `export_method` in gym and the selected provisioning profiles. You passed the following options:
export_method:
Bundle identifier: com.ourorg.ourapp.in-development-env
I had to redact a lot of proprietary information from the example, but hopefully it still make sense!
A couple of other details that might be relevant:
.env.development
gitignored.eas build:inspect --platform ios --stage archive --output ./archive --profile staging
, the .env.development
file is included in the archive.This would seem to indicate a couple of things:
.env
files, even if that's not intentional..env
files also has NODE_ENV !== production
since .env.development
is loaded.Here is another forum post where I believe someone is encountering the same issue.
Since we run our builds from a Github action, the workaround we came up with is to simply delete the .env.development
prior to running the build command. But clearly that should not be necessary!
I happy to share specific builds that repro this with someone from the development team if that helps to debug this, I'm just unable to link to them publicly.
Thanks @mattpetrie, your description totally makes sense and I can confirm I've similar config in my repo resulting in same problem. Hopefully EAS team can take a look a this one.
It seems like the issue is coming from a small detail in the documentation. When .env or other environment files are added to gitignore they will also be ignored by EAS.
Problem is that is very contradictory because if you build locally then you are relying on .env files which shouldn't be added to the git repository.
Solution: remove .env file (and others) from gitignore and the build pipeline loads the env files.
Also: The documentation suggests to only use NODE_ENV=test, development or production.
Edit: if you add a .easignore file to the directory it doesn't look for .gitignore anymore so you can gitignore .env files.
@mattpetrie I have the exact same problem as you, with pretty much an identical setup. Have you found a solution yet?
I have a possible workaround from another project that I've worked on where I use the "EXPO_NO_DOTENV": "1"
flag, and then load the environment variables myself rather than letting Expo/EAS handle it. I don't have the same issue there. Here's an example of what that setup looks like: https://github.com/obytes/react-native-template-obytes/blob/master/env.js
This definitely seems like a bug in Expo/EAS.
Build/Submit details page URL
https://expo.dev/accounts/smatsa/projects/wealth-managers-lite-app/builds/e902404a-195b-4d26-af51-160e49f49b97
Summary
After updating to SDK49, adopting
expo-router
, new way of handling envs by Expo & following this guide for apps with different APP_VARIANTS its proven to be impossible to build theproduction
provisioning profile for iOS.From what i can make out from the error logs below, apparently the bundleIdentifier from the stage variant gets in the way when trying to create the build from production profile. I guess it comes from the export_method
Gymfile
but not sure how this can be addressed. I've tried adding a customGymfile
in the/ios
folder but same error is reproduced.Managed or bare?
bare
Environment
Error output
Reproducible demo or steps to reproduce from a blank project
1) Create a project with 2 different variants 2) Build the project with
eas build --profile preview --platform ios --local
3) See logs and build complete succesffully 4) Build other variant witheas build --profile production --platform ios --local
5) See error logs with variants getting mixed up. Same error is thrown when building in eas servers