XCode 13 failed to generate profdata file - ios

We have always been using the following code in our PR pipeline for years and it worked.
xcodebuild -sdk iphoneos -configuration dev -workspace MyProject.xcworkspace -scheme MyProject_Mu -destination 'platform=iOS Simulator,name=iPhone 8' test -derivedDataPath DerivedData CODE_SIGNING_ALLOWED=NO
Normally, the above code generated .profraw and .profdata at folder: DerivedData/Build/ProfileData/41E444A5-D124-4222-82C2-EB33DCDBF2FC/
Until recently, our hosted agent upgraded from XCode 12 to XCode 13, the above code generates only the .profraw and ends with the error below
warning: DerivedData/Build/ProfileData/41E444A5-D124-4222-82C2-EB33DCDBF2FC/B8590BD3-CF44-4308-95CF-20FBFFEF3568-24496.profraw: Failed to uncompress data (zlib)
error: No profiles could be merged.
We even tried to run this code hoping this would fix the issue:
xcrun llvm-profdata merge DerivedData/Build/ProfileData/*/*.profraw -output generated.profdata
But it does not work. We get the same error
warning: DerivedData/Build/ProfileData/41E444A5-D124-4222-82C2-EB33DCDBF2FC/B8590BD3-CF44-4308-95CF-20FBFFEF3568-24496.profraw: Failed to uncompress data (zlib)
error: No profiles could be merged.
Now our PR pipeline is stuck and we can't work because this script is needed to generate unit test coverage data. And the pipeline is always failing.

I solved the issue by setting GCC_INSTRUMENT_PROGRAM_FLOW_ARCS to NO. For some reason the extra code added by LLVM profiling instrumentation is interfering with the code coverage. I am not sure if this is the expected behavior; I will file a bug and follow up if I have any further information.

Related

Xcode 10 archiving fails - only on command line (xcodebuild)

I'm having issues with archiving on my CI machine (Jenkins), when running the process manually on the SAME machine but with the Xcode UI, everything works just fine.
The error I get is:
<unknown>:0: error: cannot have input files with file list
** ARCHIVE FAILED **
The following build commands failed:
CompileSwift normal armv7
CompileSwiftSources normal armv7 com.apple.xcode.tools.swift.compiler
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
CompileSwift normal arm64
(4 failures)
The original command it's executing on failure is VERY long (68K+ characters), here it is stripped down from all pods/app info:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift #/var/folders/cc/h3hp1kt14rv3j5t_lybwwgqh0000gp/T/arguments-ece6e3.resp # -frontend -c -filelist /var/folders/cc/h3hp1kt14rv3j5t_lybwwgqh0000gp/T/sources-e4a704 -supplementary-output-file-map /var/folders/cc/h3hp1kt14rv3j5t_lybwwgqh0000gp/T/supplementaryOutputs-4e5601 -target arm64-apple-ios10.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.0.sdk -g -module-cache-path / ... /ModuleCache.noindex -swift-version 4 -O -D RELEASE -serialize-debugging-options ... -module-name APPNAME -num-threads 8 -output-filelist /var/folders/cc/h3hp1kt14rv3j5t_lybwwgqh0000gp/T/outputs-3df91d
Some more info:
Using Cocoapods 1.5.3 (also reproduces with latest 1.6.0_beta.1)
Using the "Legacy Build System"
the exact command I'm running to archive is:
xcodebuild -scheme APPSCHEME -workspace APPNAME.xcworkspace -configuration Release clean build archive -derivedDataPath "../build" -archivePath "../build/APPNAME.xcarchive"
Just to make things even more interesting, when running the archive command on my local machine I see no failures... VERY strange and inconsistent.
Any help will be appreciated!
A related case in which this error appears is by running:
xcodebuild -scheme sharetec build
In my case I just had to tune up a little more the parameters like this:
xcodebuild -workspace [WP_NAME].xcworkspace -scheme [A_TARGET] -sdk iphoneos clean build
So the error disappears.
Eventually I figured it out, it's something that looks really UNRELATED, and yet it was the only thing that fixed the described issue for me.
Go to your build settings and remove any recursive search paths you have there. That's it. (any search path that ends with ** is a recursive one).
Good luck!
I had this issue when using AppCenter. I had selected a different version of xcode to that of my project's deployment target.
I had the same issue doing:
xcodebuild -workspace ABC.xcworkspace -scheme SCHEME_NAME archive -archivePath ABC.xcarchive
I solved it by stripping out the -archivePath and its parameter.
I have a possible general solution for this issue. In my case, I followed all the advices from all the possible websites, including this one, but it was no luck until I tried archiving the project on Xcode itself (I was archiving thru fastlane, and its logs didn't help me at all). When I archived in Xcode, it actually showed me where was the problem, and I was able to quickly solve the issue. So, in case nothing works, try archiving in Xcode itself if you happen to archive outside of it.

xcodebuild: cdtool cannot compile: DataModelCompile /path/to/coredatamodel.xcdatamodeld dyld: Symbol not found: _OBJC_CLASS_$_OS_object

I'm building a Mac Desktop/Cocoa Application to archive my iOS project, the core implementation uses NSTask with xcodebuild command, followed by raywenderlich's this guide.
The root cause is the CoreData model file compile, I used this app to build my another project which didn't contain any CoreData files and no issue there. More interesting comparison is, I tried the same xcodebuild command in my terminal and it just succeed!
Then I start to diff the two xcodebuild output and found some differences,
In terminal,
DataModelCompile /Users/hanwei/Library/Developer/Xcode/DerivedData/youYue3xMaster-cjatyqmgblwyoyccarejxlozikdi/Build/Intermediates/ArchiveIntermediates/youYue3xMaster/InstallationBuildProductsLocation/Applications/youYue3xMaster.app/ youYue3xMaster/LogicBook.xcdatamodeld
cd /Users/hanwei/work/DragonSource/projects/ios_youyue3_xmaster/youYue3xMaster
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/opt/subversion/bin:/usr/local/bin:/opt/subversion/bin:/usr/local/bin:/opt/subversion/bin:/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin"
/Applications/Xcode.app/Contents/Developer/usr/bin/momc --sdkroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk --iphoneos-deployment-target 7.0 --module youYue3xMaster /Users/hanwei/work/DragonSource/projects/ios_youyue3_xmaster/youYue3xMaster/youYue3xMaster/LogicBook.xcdatamodeld /Users/hanwei/Library/Developer/Xcode/DerivedData/youYue3xMaster-cjatyqmgblwyoyccarejxlozikdi/Build/Intermediates/ArchiveIntermediates/youYue3xMaster/InstallationBuildProductsLocation/Applications/youYue3xMaster.app/
In my cocoa app's log
DataModelCompile /Users/hanwei/Library/Developer/Xcode/DerivedData/youYue3xMaster-cjatyqmgblwyoyccarejxlozikdi/Build/Intermediates/ArchiveIntermediates/youYue3xMaster/InstallationBuildProductsLocation/Applications/youYue3xMaster.app/ youYue3xMaster/MagazineModel.xcdatamodeld
cd /Users/hanwei/work/DragonSource/projects/ios_youyue3_xmaster/youYue3xMaster
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/usr/bin/momc --sdkroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk --iphoneos-deployment-target 7.0 --module youYue3xMaster /Users/hanwei/work/DragonSource/projects/ios_youyue3_xmaster/youYue3xMaster/youYue3xMaster/MagazineModel.xcdatamodeld /Users/hanwei/Library/Developer/Xcode/DerivedData/youYue3xMaster-cjatyqmgblwyoyccarejxlozikdi/Build/Intermediates/ArchiveIntermediates/youYue3xMaster/InstallationBuildProductsLocation/Applications/youYue3xMaster.app/
dyld: Symbol not found: _OBJC_CLASS_$_OS_object
Referenced from: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/lib/system/libxpc.dylib
Expected in: /usr/lib/system/introspection/libdispatch.dylib in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/lib/system/libxpc.dylib
2016-06-17 09:46:28.158 momc[76594:13533677] *** -[NSKeyedUnarchiver initForReadingWithData:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?
cdtool invalid hashes:
/Users/hanwei/work/DragonSource/projects/ios_youyue3_xmaster/youYue3xMaster/youYue3xMaster/MagazineModel.xcdatamodeld/MagazineModel.xcdatamodel:: error: cdtool cannot compile
The main error log detail could be found in later part, the diff result is "export PATH=...". In terminal, the PATH contains the current user's ${PATH}, I through that should be the final cause, but no luck there after trying to export the same path to my cocoa app's shell script.
Here is my shell script,
command -v xcodebuild >/dev/null 2>&1 || { echo >&2 "It requires xcodebuild but it's not installed. Aborting."; exit 1; }
#export PATH=$PATH:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/opt/subversion/bin:/usr/local/bin:/opt/subversion/bin:/usr/local/bin:/opt/subversion/bin:/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin
#PATH=$PATH:/opt/subversion/bin:/usr/local/bin:/opt/subversion/bin:/usr/local/bin:/opt/subversion/bin:/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin
echo ${PATH}
type xcodebuild
type xcpretty
if [ -x "$(command -v xcpretty)" ]; then
xcodebuild -workspace "${1}" -scheme "${2}" -sdk iphoneos -destination generic/platform=iOS -archivePath "${3}" archive | xcpretty
else
echo "xcpretty is not installed, suggest to install it and try again.";
xcodebuild -workspace "${1}" -scheme "${2}" -sdk iphoneos -destination generic/platform=iOS -archivePath "${3}" archive
fi
For the error "dyld: Symbol not found: _OBJC_CLASS_$_OS_object...", I googled it and found that _OBJC_CLASS_$_OS_object symbol built from libdispach, libdispatch should be built in Foundation.framework, then I tried to link Foundation.framework in my project explicitly, the same error exists.
For the "Referenced from:...Expected in:..."* statement, it references to iPhone simulator, then I guess there maybe something wrong about xcodebuild -destination, passing generic/platform=iOS or my iOS device (references from this cheetsheet) doesn't work, either.
For "error: cdtool cannot compile", I found this big question related in Xcode bug, .xcdatamodel: cdtool cannot compile, I tried the rename solution and no luck, that question background is for Xcode beta version.
Currently my environment is Xcode 7.3.1 (7D1014), 10.11.5 (15F34).
I've focus on this issue over 8 hours, If you have some good suspect points or solutions, please help me, great thanks in advance!
BTW, I found #MichalMoskala encountered the same problem and no solution there, Calling xcodebuild from Swift command line tool fails. He didn't statement the background it happened in Xcode-beta version.
If there is really no final solutions, I have to decide to transit CoreData to FMDB/Realm.
UPDATE
SOLUTION
After several days' investigation, I didn't find a real final solution for this, it should be bug in Xcode when compiling xcdatamodeld file in xcodebuild by hand. But why not appear in Xcode IDE? Maybe Apple developers made some patches in Xcode.
Here is my solution, copy the compiled xcdatamodeld files (*.momd) to project, remove the *.xcdatamodeld file from Build Phrases - Compile Sources in project, so that they will not be compiled when building/archiving. Add custom script to copy the .momd backup files to product directory, it's executed before Compile Sources, just like the build progress in Xcode.
Here is my script,
cp -r ${SRCROOT}/CoreDataFiles/*.momd ${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/
Validation passed!

EXPORT FAILED error using xcodebuild command line tool

I'm trying to export an ipa file through xcodebuild but I always receive this error.
IDEDistribution: Step failed: : Error Domain=IDEDistributionErrorDomain Code=14 "No
applicable devices found." UserInfo={NSLocalizedDescription=No
applicable devices found.} error: exportArchive: No applicable devices
found.
Error Domain=IDEDistributionErrorDomain Code=14 "No applicable devices
found." UserInfo={NSLocalizedDescription=No applicable devices found.}
** EXPORT FAILED **
Any hint?
This is the shell script I'm using (run in terminal through sh export_script.sh)
xcodebuild clean -project 'MyProject.xcodeproj' -configuration Debug -scheme MyProject -alltargets
xcodebuild -project 'MyProject.xcodeproj' -scheme MyProject archive -archivePath 'MyProject.xcarchive'
xcodebuild -exportArchive -archivePath 'MyProject.xcarchive' -exportPath 'Export' -exportOptionsPlist 'Options.plist'
P.S. Point me out any error in my scripts, if present.
I'm not sure, but probably you should specify you need a build for a device.
You need to add -sdk with proper value (depends on iphoneos with version number)
The old way to do it seems to do the job.
xcodebuild -exportArchive -archivePath $XCODE_ARCHIVE -exportPath $EXPORT_PATH -exportFormat ipa -exportProvisioningProfile "$PROVISIONING_PROFILE" -configuration $CONFIGURATION
where $PROVISIONING_PROFILE is for example iOS Development. The archive is created correctly. The shell will print out a deprecation log. You can safely ignore it.
The new way, introduced with Xcode does not work (at least for me). See xcodebuild's new exportOptionsPlist flag.
If you have any hint to use the new way, please post it.
Edit
There is an open radar for it Open Radar. In addition, also Fastlane provides a fallback mechanism for this problem (see Export Failed with Xcode 7 - No applicable devices found).
In my case the issue was related to using RVM. Switching to the system Ruby solved the issue:
rvm use system
Seams like some parts of xcodebuild are relying on the system version of Ruby and don't play nice with RVM.

Code sign validation failing during xcodebuild and Failed to read entitlements for xcrun

I have tried every available solution over here and on the internet.
I am trying to automate the iOS build process, and the clean, build and archive process succeed with these 5 warnings (errors) failing code sign validation.
warning: The CodeResources file is missing and it must be a symbolic link to _CodeSignature/CodeResources. Make certain that the bundle is on a locally-mounted volume (not a remote SMB volume), and be certain to use the Mac OS X Finder to compress it (-19062)
Unable to validate your application. - (null)
warning: iPhone/iPod Touch: application executable is missing a required architecture. At least one of the following architecture(s) must be present: armv6 (-19033)
Unable to validate your application. - (null)
warning: Icon specified in the Info.plist not found under the top level app wrapper: (-19007)
Unable to validate your application. - (null)
warning: iPhone/iPod Touch: Info.plist: Unable to verify icon dimensions, no icon found. Your MinimumOSVersion is below 3.2, so you must define CFBundleIconFile or provide a default Icon.png that is 57x57. (-19013)
Unable to validate your application. - (null)
warning: Application failed codesign verification. The signature was invalid, contains disallowed entitlements, or it was not signed with an iPhone Distribution Certificate. (-19011)
If i try to ignore the warning or use the debug config to skip validating the codesign, xcrun to package the .app to .ipa fails with following error
env SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication -v
/Users/XXXXXX/source/digital_hub/cms/final/cms_repo/H1/45/ZD/0v/U9/Rr/gT/builds/Test_22_07_13_11_31_23.app -o
/Users/XXXXX/source/digital_hub/cms/final/cms_repo/H1/45/ZD/0v/U9/Rr/gT/builds/Test_22_07_13_11_31_23.ipa
--sign iPhone\ Distribution
--embed/Users/XXXXXXX/source/digital_hub/cms/cms_local_repo/6072/76/XXXXXXXX_AppStore_11_07_1373971044.mobileprovision
error: Failed to read entitlements from '/var/folders/n6/8tsx1pss5v3fq3sfpz8379r0ms3b7m/T/Rm5MudWNER/Payload/Test_22_07_13_11_31_23.app'
My xcodebuild command is following as I am working with workspaces
/usr/bin/xcodebuild -verbose
-workspace /Users/XXXXX/source/digital_hub/cms/git_local_repo/11330/80/PDFReader.git/XXXXXX.xcworkspace
-scheme _DEFAULT -sdk iphoneos -configuration Release CODE_SIGN_IDENTITY="iPhone Distribution:"
PROVISIONING_PROFILE=73DE6F20-FAB9-46A2-9825-35D7DE82CD4D
CONFIGURATION_BUILD_DIR=/Users/ahsandar/source/digital_hub/cms/final/cms_repo/H1/45/ZD/0v/U9/Rr/gT/builds/Test_22_07_13_13_26_29.app
OTHER_CODE_SIGN_FLAGS="--keychain /tmp/xcoder1374496105" clean
My xcrun command looks like this
/usr/bin/xcrun -log -sdk iphoneos PackageApplication -v
"/Users/XXXXX/source/digital_hub/cms/final/cms_repo/H1/45/ZD/0v/U9/Rr/gT/builds/Test_22_07_13_13_26_29.app" -o
"/Users/XXXXX/source/digital_hub/cms/final/cms_repo/H1/45/ZD/0v/U9/Rr/gT/builds/Test_22_07_13_13_26_29.ipa" --sign "iPhone Distribution:"
--embed "/Users/XXXXX/source/digital_hub/cms/cms_local_repo/11330/80/XXXXXX_AppStore_11_07_1373
I am using xcoder gem to create temporary keychain to add my p12 in it. all verification on the archive are successful using the command line tools for codesign.
Looks like you have set minimus os smaller than possible in project settings, possible your icons have wrong size. Please read again your first log.
And be sure that you provide correct params to xcodebuild command.
For me clean works good with these args:
xcodebuild clean -sdk iphoneos5.1 -project '${PBXPROJ}.xcodeproj' -configuration '${MCONFIG}' -alltargets DSTROOT="${RELEASE_BUILDDIR}" PROVISIONING_PROFILE="${kPROVISONING_PROFILE}" CODE_SIGN_IDENTITY="${DEVELOPER_NAME}"
And build works good like that:
xcodebuild install -sdk iphoneos5.1 -project "${PBXPROJ}.xcodeproj" -configuration "${MCONFIG}" -target "${TARGET}" DSTROOT="${RELEASE_BUILDDIR}" PROVISIONING_PROFILE="${kPROVISONING_PROFILE}" CODE_SIGN_IDENTITY="${DEVELOPER_NAME}"
Hope it helps.

xcodebuild archiving issue

I'm having an issue with xcodebuild. I use the xcodebuild archive command from a build server to create an archive. At the moment, it seems that it will not respect the build configuration I have set. Has anyone come across this, or have any idea how to alter it?
To give a bit more background, within the project I have my build location set as Legacy so that I can build multiple libraries into a single iOS app (similar to how three20 do it), and so I have my build directories set within an xcconfig file as so:
BUILD_DIR = ../Build
SYMROOT = ${BUILD_DIR}/Products
OBJROOT = ${BUILD_DIR}/Intermediates
TEMP_ROOT = ${BUILD_DIR}/Temp
If I run
xcodebuild -workspace ${WORKSPACE} -scheme ${SCHEME} -configuration ${CONFIGURATION} -sdk ${SDK}
It all works swimmingly, and the compilation command I get compiles into the common ../Build folder as you can see in the sample output here:
CompileC ../Build/Intermediates/Core.build/Release-iphoneos/Core.build/Objects-normal/armv7s/NumberUtils.o Source/NumberUtils.m normal armv7s objective-c com.apple.compilers.llvm.clang.1_0.compiler
However if I add archive on the end, and run:
xcodebuild -workspace ${WORKSPACE} -scheme ${SCHEME} -configuration ${CONFIGURATION} -sdk ${SDK} archive
It ignores my build settings, and just uses the DerivedData location:
CompileC /Users/user/Library/Developer/Xcode/DerivedData/workspace-bmancqbwwpbxuzbdtxezsoptpyur/ArchiveIntermediates/Release/IntermediateBuildFilesPath/Core.build/Release-iphoneos/Core.build/Objects-normal/armv7/NumberUtils.o Source/NumberUtils.m
Is there something else I need to set? I've set all the environment variables I can think of. Strangely archiving from within xcode itself also works fine. Any advice?

Resources