Xcode Archive succeeds but xcodebuild archive fails during fastlane step

I’m using expo@41.0.0 with the bare workflow, and eas-cli@0.14.1.

This might not be an issue with EAS Build itself, but the issue is preventing me from using eas build for iOS, so I’d appreciate any advice on how to debug this.

When I run eas build --platform ios --profile preview the build starts successfully, but fails on the “Run fastlane” step. I’ve tried several times and it always fails with the same error. Here’s the error message:

$ set -o pipefail && xcodebuild -workspace ./crystaldatingapp.xcworkspace -scheme crystaldatingapp -configuration Release -destination 'generic/platform=iOS' -archivePath /Users/expo/Library/Developer/Xcode/Archives/2021-05-11/ios\ 2021-05-11\ 14.09.08.xcarchive archive | tee /Users/expo/Library/Logs/gym/ios-crystaldatingapp.log > /dev/null
55
▸ ** ARCHIVE FAILED **
56
▸ The following build commands failed:
57
▸ 	PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/expo/Library/Developer/Xcode/DerivedData/crystaldatingapp-avffxevojpksjnascnzicjswizbi/Build/Intermediates.noindex/ArchiveIntermediates/crystaldatingapp/IntermediateBuildFilesPath/crystaldatingapp.build/Release-iphoneos/crystaldatingapp.build/Script-00DD1BFF1BD5951E006B06BC.sh
58
▸ (1 failure)
59
** ARCHIVE FAILED **
60
61
62
The following build commands failed:
63
	PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/expo/Library/Developer/Xcode/DerivedData/crystaldatingapp-avffxevojpksjnascnzicjswizbi/Build/Intermediates.noindex/ArchiveIntermediates/crystaldatingapp/IntermediateBuildFilesPath/crystaldatingapp.build/Release-iphoneos/crystaldatingapp.build/Script-00DD1BFF1BD5951E006B06BC.sh
64
(1 failure)
65
Exit status: 65

As suggested by fastlane output, I tried copying the command it’s running into my local terminal and running it. This is the command that I’m running:

xcodebuild -workspace ./crystaldatingapp.xcworkspace -scheme crystaldatingapp -configuration Release -destination 'generic/platform=iOS' -archivePath /Users/expo/Library/Developer/Xcode/Archives/2021-05-11/ios\ 2021-05-11\ 14.09.08.xcarchive archive

But when I run that I get a different error message than what I see in fastlane. Here’s the error message:

** ARCHIVE FAILED **


The following build commands failed:
	CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
	CompileSwift normal arm64
(2 failures)

There’s also a very long output that I can include if it’s helpful, but I don’t see any obvious errors in the output, and I tried grepping the output for the error message I saw in fastlane, but it’s not in there.

But it’s weird to me that archiving from Xcode works fine, so I tried to figure out what Xcode was doing differently than this xcodebuild command. That was also the recommendation from this StackOverflow thread. I looked carefully at the logs when Xcode does an Archive, but there are no errors (there are a lot of warnings though). I also searched through the logs to see if I could find what xcodebuild command it’s using under-the-hood, but as far as I can tell, Xcode doesn’t actually use xcodebuild (please let me know if I’m wrong about this). The only command I found in the Xcode logs was a bunch of rsync commands.

I also tried deleting and reinstalling my Pods, and deleting and recreating my Podfile.lock file, neither of which made a difference. The only other thing I can think of trying at this point is creating a new expo project with the bare workflow and porting all of my code over, but I’d like to avoid that if possible.

this means your js bundle is failing. the xcode logs (which show up at the bottom of your build page after it finishes) will give you more information on this. maybe your app depends on some environment variable (through process.env.VARIABLE) that is available on your local machine but not when you push to eas build. if you share a link to your build page i can help you find the specific error message

1 Like

Thanks @notbrent ! I found it. That’s really helpful, I wouldn’t have thought to check there (I was only looking at the sections with red Xs).

The error message I found in the logs is:

Error: @build-script-error-begin
Error loading assets JSON from Metro. Ensure you've followed all expo-updates installation steps correctly. Unable to resolve module ./aws-exports from /Users/expo/workingdir/build/App.js

This is a file used by aws-amplify that contains moderately sensitive values, so the file is in my gitignore file. I’m guessing that eas build isn’t receiving this file because it’s gitignored. Is the recommendation to remove that file from my gitignore and use environment variables?

right, we only upload files that are included in git. you could add the contents to your secrets and then write it to the aws-exports file in a prebuild hook: Integrating with JavaScript tooling - Expo Documentation

2 Likes

Thanks again, I was able to resolve my problem. Still getting a build failure, but at least it’s a new error and I know how to debug it.

For anyone else having trouble with EAS not finding aws-exports.js, I created the following shell script you can use to generate it (I saved it as generate-aws-exports.sh in my project root):

#!/bin/bash

echo "const awsmobile = {
    aws_project_region: \"us-east-1\",
    aws_cognito_identity_pool_id: \"${AWS_COGNITO_IDENTITY_POOL_ID}\",
    aws_cognito_region: \"us-east-1\",
    aws_user_pools_id: \"${AWS_USER_POOLS_ID}\",
    aws_user_pools_web_client_id: \"${AWS_USER_POOLS_WEB_CLIENT_ID}\",
    oauth: {},
    aws_user_files_s3_bucket: \"${AWS_USER_FILES_S3_BUCKET}\",
    aws_user_files_s3_bucket_region: \"us-east-1\",
};

export default awsmobile;" > aws-exports.js

You may need to use chmod on it to make the script executable.
Then add those 4 environment variables to your Secrets through the EAS Build website.

And finally, add this line to your package.json:

"scripts": {
   // Add this to your existing list of scripts
    "eas-build-pre-install": "sh generate-aws-exports.sh"
  },

Using eas-build-post-install instead would probably work fine too.

1 Like