EXPORT FAILED error using xcodebuild command line tool - ios

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.

Related

XCode 13 failed to generate profdata file

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.

Getting IOS development build error

Development build get the following error during export, it shows that archive succeeded. Also the app store distribution build passes. I used the cert tool to generate all certs for this.
The full build log is here:
Build log
Here is the messages that look like the cause of the failure:
** ARCHIVE SUCCEEDED **
Executing: echo /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -exportArchive -archivePath rvgame.xcarchive -exportPath /var/folders/p_/xlvwhg4101z8r81_nl13cds80000gn/T/build4175955742863989776xxx/result -exportOptionsPlist /var/folders/p_/xlvwhg4101z8r81_nl13cds80000gn/T/export4912377426492049316.plist -verbose PROVISIONING_PROFILE=4b697edf-96fe-4b7a-ae88-07eaa148026f CODE_SIGN_IDENTITY=iPhone Developer: samuel lotti (V8JNGG63WU) KEYCHAIN=/Users/administrator/Library/Keychains/temp1513260206451.keychain CODE_SIGN_ENTITLEMENTS=/var/folders/p_/xlvwhg4101z8r81_nl13cds80000gn/T/Entitlements4983206492678257794.plist /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -exportArchive -archivePath rvgame.xcarchive -exportPath /var/folders/p_/xlvwhg4101z8r81_nl13cds80000gn/T/build4175955742863989776xxx/result -exportOptionsPlist /var/folders/p_/xlvwhg4101z8r81_nl13cds80000gn/T/export4912377426492049316.plist -verbose PROVISIONING_PROFILE=4b697edf-96fe-4b7a-ae88-07eaa148026f CODE_SIGN_IDENTITY=iPhone Developer: samuel lotti (V8JNGG63WU) KEYCHAIN=/Users/administrator/Library/Keychains/temp1513260206451.keychain CODE_SIGN_ENTITLEMENTS=/var/folders/p_/xlvwhg4101z8r81_nl13cds80000gn/T/Entitlements4983206492678257794.plist
Executing: /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -exportArchive -archivePath rvgame.xcarchive -exportPath /var/folders/p_/xlvwhg4101z8r81_nl13cds80000gn/T/build4175955742863989776xxx/result -exportOptionsPlist /var/folders/p_/xlvwhg4101z8r81_nl13cds80000gn/T/export4912377426492049316.plist -verbose PROVISIONING_PROFILE=4b697edf-96fe-4b7a-ae88-07eaa148026f CODE_SIGN_IDENTITY=iPhone Developer: samuel lotti (V8JNGG63WU) KEYCHAIN=/Users/administrator/Library/Keychains/temp1513260206451.keychain CODE_SIGN_ENTITLEMENTS=/var/folders/p_/xlvwhg4101z8r81_nl13cds80000gn/T/Entitlements4983206492678257794.plist 2017-12-14 08:05:38.785 xcodebuild[42364:31715511] [MT] IDEDistribution: -[IDEDistributionLogging _createLoggingBundleAtPath:]: Created bundle at path '/var/folders/p_/xlvwhg4101z8r81_nl13cds80000gn/T/rvgame_2017-12-14_08-05-38.784.xcdistributionlogs'.
2017-12-14 08:05:38.825 xcodebuild[42364:31715511] [MT] DeveloperPortal: Using pre-existing current store at URL (file:///Users/administrator/Library/Developer/Xcode/DeveloperPortal%207.3.1.db).
2017-12-14 08:05:59.053 xcodebuild[42364:31715511] [MT] 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 **
Not sure how to fix this.
This was a problem with new Xcode requirements on static libraries. The Admob and Flurry static libs were compiled with an older version of Xcode which didn't include LC_VERSION_MIN_IPHONEOS run commands, and ipatool now crashes if it encounters a library that doesn't include this.
I have updated both the Admob and the Flurry cn1libs to use Cocoapods instead of the static library directly, and this will fix the issue. These will be available in Codename One Settings after the next server update (this week). If you need them before then, you can download and install the cn1libs directly:
https://github.com/codenameone/CodenameOneLibs/raw/master/cn1libs/CN1Flurry.cn1lib
https://github.com/codenameone/CodenameOneLibs/raw/master/cn1libs/AdmobFullScreen.cn1lib
I have also made some changes on the build server to add a more descriptive error message when it detects this scenario. That will also be updated in the next build server update.

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!

Build Project From Terminal throws Provisioning Profile error

I am trying to create ipa of my application using terminal.
I am able to successfully build my application, but when converting into an ipa, it throws the following error:
Check dependencies
Code Sign error: No matching provisioning profile found: Your build settings specify a provisioning profile with the UUID “/Users/xxxx/Downloads/Certificate/xxxx.mobileprovision”, however, no such provisioning profile was found.
CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 7.0'
** ARCHIVE FAILED **
When I try to build the same application using X-Code, it works fine with the same provisioning profile.
The script I am running to build the ipa is
xcodebuild -verbose -project Build_Project_From_Terminal.xcodeproj -scheme nameOfProject -configuration Release -sdk iphoneos clean archive CONFIGURATION_BUILD_DIR="/Users/xxxx/Desktop/xxxx/Project Name/build" PROVISIONING_PROFILE="/Users/xxxxx/Downloads/Certificate/xxxxx.mobileprovision"
EDIT 1:
I have changed my script to
DEVELOPER_NAME="xxxxxxxxx" APP_NAME="xxxxxx"
xcodebuild archive -project $APP_NAME.xcodeproj -scheme $APP_NAME -archivePath ./$APP_NAME.xcarchive
xcodebuild -exportArchive -exportFormat APP -archivePath ./$APP_NAME.xcarchive -exportPath ./$APP_NAME.ipa
iphoneos PackageApplication -v ./$APP_NAME.app -o ./$APP_NAME.ipa --sign $DEVELOPER_NAME --embed ./*.mobileprovision
With this I am getting $APP_NAME.ipa.app as output. When I try to install this, it does not install at all.
Any help will be appreciated.
Please use an alternate method. This is a working example
DEVELOPER_NAME="Your apple developer name"
APP_NAME="application name"
xcodebuild archive -workspace $APP_NAME.xcworkspace -scheme $APP_NAME -archivePath ./$APP_NAME.xcarchive
xcodebuild -exportArchive -exportFormat APP -archivePath ./$APP_NAME.xcarchive -exportPath ./$APP_NAME.ipa
iphoneos PackageApplication -v ./$APP_NAME.app -o ./$APP_NAME.ipa --sign $DEVELOPER_NAME --embed ./*.mobileprovision
Save above shell script in a file (abc.sh) and save that file in your project folder along with your provision profile. Run this script using terminal will save ipa in the project directory.

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.

Resources