Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug build iOS with SDK49 with multiple scheme #2009

Open
lukasver opened this issue Aug 17, 2023 · 8 comments
Open

Bug build iOS with SDK49 with multiple scheme #2009

lukasver opened this issue Aug 17, 2023 · 8 comments
Labels
needs review Issue is ready to be reviewed by a maintainer

Comments

@lukasver
Copy link

lukasver commented Aug 17, 2023

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 the production 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 custom Gymfile in the /ios folder but same error is reproduced.

Managed or bare?

bare

Environment

  expo-env-info 1.0.5 environment info:
    System:
      OS: macOS 13.5
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 16.18.1 - ~/.nvm/versions/node/v16.18.1/bin/node
      Yarn: 1.22.10 - /usr/local/bin/yarn
      npm: 8.19.2 - ~/.nvm/versions/node/v16.18.1/bin/npm
      Watchman: 2023.06.26.00 - /opt/homebrew/bin/watchman
    Managers:
      CocoaPods: 1.12.1 - /usr/local/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
      Android SDK:
        API Levels: 31, 33, 33
        Build Tools: 30.0.3, 31.0.0, 33.0.0, 33.0.1
        System Images: android-33 | Google APIs ARM 64 v8a
    IDEs:
      Android Studio: 2022.1 AI-221.6008.13.2211.9514443
      Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild
    npmGlobalPackages:
      eas-cli: 4.1.2
      expo-cli: 6.3.2

✔ Validating global prerequisites versions passed
✔ Checking for incompatible packages passed
✔ Checking for conflicting global packages in project passed
✔ Verifying prebuild support package versions are compatible passed
✔ Checking dependency versions for compatibility with the installed Expo SDK passed
NOT SUPPORTED: option format. `validateFormats: false` can be used instead.
✔ Validating Expo Config passed
✔ Checking package.json for common issues passed

Didn't find any issues with the project!

Error output

[RUN_FASTLANE] $ set -o pipefail && xcodebuild -workspace ./SmatApp.xcworkspace -scheme SmatApp -configuration Release -destination 'generic/platform=iOS' -archivePath /Users/lucas/Library/Developer/Xcode/Archives/2023-08-17/SmatApp\ 2023-08-17\ 17.43.09.xcarchive archive | tee /var/folders/th/lk3sf7417gl65xlvl7y60v7r0000gn/T/eas-build-local-nodejs/90c7ab2a-d0fd-4761-94d6-b7b431f080f6/logs/SmatApp-SmatApp.log > /dev/null
[RUN_FASTLANE] ▸ 2023-08-17 17:43:10.048 xcodebuild[30360:285224] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
[RUN_FASTLANE]     Run script build phase '[CP-User] Generate app.manifest for expo-updates' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'EXUpdates' from project 'Pods')
[RUN_FASTLANE]     Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'React-utils' from project 'Pods')
[RUN_FASTLANE]     Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'RCT-Folly' from project 'Pods')
[RUN_FASTLANE]     Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'React-runtimescheduler' from project 'Pods')
[RUN_FASTLANE]     Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'fmt' from project 'Pods')
[RUN_FASTLANE]     Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'React-Codegen' from project 'Pods')
[RUN_FASTLANE]     Run script build phase '[CP-User] Generate app.config for prebuilt Constants.manifest' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'EXConstants' from project 'Pods')
[RUN_FASTLANE]     Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'ReactCommon' from project 'Pods')
[RUN_FASTLANE]     Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'React-NativeModulesApple' from project 'Pods')
[RUN_FASTLANE]     Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'React-debug' from project 'Pods')
[RUN_FASTLANE]     Run script build phase 'Start Packager' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'SmatApp' from project 'SmatApp')
[RUN_FASTLANE]     Run script build phase 'Bundle React Native code and images' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'SmatApp' from project 'SmatApp')
[RUN_FASTLANE]     Run script build phase '[CP-User] [RNFB] Core Configuration' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'SmatApp' from project 'SmatApp')
[RUN_FASTLANE] ▸ ** ARCHIVE FAILED **
[RUN_FASTLANE] 2023-08-17 17:43:10.048 xcodebuild[30360:285224] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
[RUN_FASTLANE] ** ARCHIVE FAILED **
[RUN_FASTLANE] Exit status: 65
[RUN_FASTLANE] 
[RUN_FASTLANE] +-------------+-------------------------+
[RUN_FASTLANE] |           Build environment           |
[RUN_FASTLANE] +-------------+-------------------------+
[RUN_FASTLANE] | xcode_path  | /Applications/Xcode.app |
[RUN_FASTLANE] | gym_version | 2.214.0                 |
[RUN_FASTLANE] | sdk         | iPhoneOS16.4.sdk        |
[RUN_FASTLANE] +-------------+-------------------------+
[RUN_FASTLANE] 
[RUN_FASTLANE] There seems to be a mismatch between your provided `export_method` in gym
[RUN_FASTLANE] and the selected provisioning profiles. You passed the following options:
[RUN_FASTLANE] export_method:
[RUN_FASTLANE] Bundle identifier:  com.smatsa.smatapp.stage
[RUN_FASTLANE] Profile name:       *[expo] com.smatsa.smatapp AppStore 2023-08-17T16:41:54.140Z
[RUN_FASTLANE] Profile type:       app-store
[RUN_FASTLANE] Make sure to either change the `export_method` passed from your Fastfile or CLI
[RUN_FASTLANE] or select the correct provisioning profiles by updating your Xcode project
[RUN_FASTLANE] or passing the profiles to use by using match or manually via the `export_options` hash
[RUN_FASTLANE] 
[RUN_FASTLANE] Looks like fastlane ran into a build/archive error with your project
[RUN_FASTLANE] It's hard to tell what's causing the error, so we wrote some guides on how
[RUN_FASTLANE] to troubleshoot build and signing issues: https://docs.fastlane.tools/codesigning/getting-started/
[RUN_FASTLANE] Before submitting an issue on GitHub, please follow the guide above and make
[RUN_FASTLANE] sure your project is set up correctly.
[RUN_FASTLANE] fastlane uses `xcodebuild` commands to generate your binary, you can see the
[RUN_FASTLANE] the full commands printed out in yellow in the above log.
[RUN_FASTLANE] Make sure to inspect the output above, as usually you'll find more error information there
[RUN_FASTLANE] 
[RUN_FASTLANE] [!] Error building the application - see the log above
[RUN_FASTLANE] Error: The "Run fastlane" step failed with an unknown error. Refer to "Xcode Logs" below for additional, more detailed logs.
[CLEAN_UP_CREDENTIALS] Destroying keychain - /var/folders/th/lk3sf7417gl65xlvl7y60v7r0000gn/T/turtle-v2-f1a355e8-e7e2-4e4f-b933-9b1193a6c046.keychain
[CLEAN_UP_CREDENTIALS] Removing provisioning profile


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 with eas build --profile production --platform ios --local
  5. See error logs with variants getting mixed up.
    Same error is thrown when building in eas servers
@lukasver lukasver added the needs review Issue is ready to be reviewed by a maintainer label Aug 17, 2023
@lukasver
Copy link
Author

lukasver commented Aug 19, 2023

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.

@brentvatne
Copy link
Member

brentvatne commented Aug 23, 2023

@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

@Pcummings
Copy link

I am also seeing this issue, here is a link to my latest build.

https://expo.dev/accounts/fairtasting/projects/fairTasting/builds/82f6ee4d-8dfb-4043-b456-4dca675d7e7c

@lukasver
Copy link
Author

lukasver commented Oct 17, 2023

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).

image

My guess some sub shell running with NODE_ENV !== production?

@mattpetrie
Copy link

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:

  • We do not have .env.development gitignored.
  • When we run 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:

  • An EAS build step is at some point loading env variables from .env files, even if that's not intentional.
  • Whatever shell is loading those .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.

@lukasver
Copy link
Author

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.

@hamedb89
Copy link

hamedb89 commented Dec 27, 2023

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.

@AdamGerthel
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review Issue is ready to be reviewed by a maintainer
Projects
None yet
Development

No branches or pull requests

6 participants