While generating archiving build, the following error occurs. Running the app on the simulator or device, everything works fine. Previously there were no error with Xcode 11 and iOS 13.*.
Archiving app in XCode 12.0 or 12.3 gives the following error:
mkdir -p /Users/artemumanets/Library/Developer/Xcode/DerivedData/App-fuhwlkmrhjyszfaeoepbbjmjjzzi/Build/Intermediates.noindex/ArchiveIntermediates/App Staging/BuildProductsPath/Release (Staging)-iphoneos/App Staging.app/Frameworks
Symlinked...
Command PhaseScriptExecution failed with a nonzero exit code
While archiving, it is supposed to work with out errors.
An error is occurring while building the app, from Xcode or fastlane.
CocoaPods : 1.10.0
Ruby : ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
RubyGems : 3.0.3
Host : macOS 11.1 (20C69)
Xcode : 12.3 (12C33)
Git : git version 2.24.3 (Apple Git-128)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib
Repositories : cocoapods - git - https://github.com/CocoaPods/Specs.git @ f523a889245860ba8c441a3373f73073b550a22a
Please upload a sample app demonstrating the issue with minimal cocoapods reproducible steps.
It is a huge project that belongs to a company where I work. If I create a smaller demo, probably everything will work as expected.
If you are not able to help me without a project and if possible, can you guide me to understand if the last line (before command exit) "Symlinked..." is executed or not, or it is the one that is breaking the script.
If that is not the case, what is next cocoapods internal script or step is executed after the Symlinking?
Or is there any way to enable more detailed logging to get a better look where it is failing?
Because the error is not explicit at all.
@artemumanets its coming from this https://github.com/CocoaPods/CocoaPods/blob/master/lib/cocoapods/generator/embed_frameworks_script.rb#L85
@dnkoutso thank you, I will check if it helps me.
If you do figure it out and you believe its a bug in cocoapods that can handle something better lets make a PR!
Ok, I'm still researching, couldn't figure it out yet.
@dnkoutso
The following line is failing in the script that you have shared:
https://github.com/CocoaPods/CocoaPods/blob/master/lib/cocoapods/generator/embed_frameworks_script.rb#L86
source="$(readlink "${source}")"
Do you now what can cause this?
I wasn't able to find the reason for this error to occur.
I've tried to comment the line of code in my Pods-AppName-framework.sh that was causing the app to crash, and the build has succeeded, I've tested the app and everything looks ok.
I'm not sure where is the root of the problem, but this has at least temporarily solved the issue.
So for now I added the following Build Phase Script, just before [CP] Embed Pods Frameworks:
# This script is used to fix a deploy process crash by commenting a line of code in Pods-AppName-frameworks.sh that was causing archiving process to fail
echo "Fixing Pods-AppName-frameworks.sh"
SRC_STR=' source="$(readlink "${source}")"'
DST_STR=' #source="$(readlink "${source}")"'
sed -i -e "s/${SRC_STR}/${DST_STR}/g" ${PODS_ROOT}"/Target Support Files/Pods-AppName/Pods-AppName-frameworks.sh"
echo "Done Fixing Pods-AppName-frameworks.sh"
The script automatically comments the line of code that is causing the archive process to fail.
I added it as a build phase, because the Pods-AppName-frameworks.sh script is replaced every time I do pod install, so this way it always works.
@artemumanets it looks like you have a symlink somewhere in the framework and cocoapods is meant to take care of that but it doesnt.
@artemumanets 's solution worked well for me. I'm seeing this issue when precompiling pods using https://github.com/leavez/cocoapods-binary - and looks like there're more folks facing this same issue when precompiling using other tools as you can see above ☝️
May be an issue the precompile tools, but for the time being idk how to fix them other than using this dirty workaround. I have no idea why deleting the source="$(readlink "${source}")" works 😬 but it does - I tested building, archiving, exporting and uploading to the App Store and validating against Apple's servers, and launching and playing around with the app in TestFlight. So, so far this solution's 💯 thanks a lot @artemumanets
@rogerluan, I also found it to be a problem of cocoapods-binary. This problem is actually coming from the readlink() wrapper implementation cocoapods-binary is adding. This cocoapods-binary readlink() implementation does not correctly escape the path. My project name did contain spaces resulting in failing readlink calls. I did fix it using the updated version of @artemumanets script. Probably better than just removing it as it would miss some of the symlinks in your package.
SRC_STR=' path=`$old_read_link $1`;'
DST_STR=' path=`$old_read_link "$1"`;'
sed -i -e "s/${SRC_STR}/${DST_STR}/g" "${PODS_ROOT}/Target Support Files/Pods-AppName/Pods-AppName-frameworks.sh"
echo "Done fixing Pods-AppName-frameworks.sh"
@thomaswinkler that is amazing! Yes, this is a lot better, and also comforts me knowing the root cause of the issue 🤗
I have tested your solution and it works great!
Also, worth noting that there has already been a fix to cocopods-binary, opened in Dec 2019 and merged in Sep 2020 (😢 ), but still unreleased 😭 https://github.com/leavez/cocoapods-binary/pull/107
As cocoapods-binary-cache was built on top of cocoapods-binary, it faced it same issue. I just opened a PR to fix it there too: https://github.com/grab/cocoapods-binary-cache/pull/67
Most helpful comment
@rogerluan, I also found it to be a problem of cocoapods-binary. This problem is actually coming from the readlink() wrapper implementation cocoapods-binary is adding. This cocoapods-binary readlink() implementation does not correctly escape the path. My project name did contain spaces resulting in failing readlink calls. I did fix it using the updated version of @artemumanets script. Probably better than just removing it as it would miss some of the symlinks in your package.