xcodebuild: build Mac OS app - xcode

I'd like to do automating for my Mac App project.
My environment is Mac OS 10.8.3; Xcode 4.6.
I use the following command in the terminal:
xcodebuild -project pro.xcodeproj -target MyProject -configuration Debug CODE_SIGN_IDENTITY='Mac Developer: xxxxxx'
It ran well and I could see the MyProject.app was created in the workspace: /build/Debug.
Then I just copied it to the Jenkins configurations, like:
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer/
xcodebuild -project pro.xcodeproj -target MyProject -configuration Debug CODE_SIGN_IDENTITY='Mac Developer: xxxxxx'
However, the build always failed with :
Code Sign error: Provisioning profile 'EADA149E-1A30-4C3C-B42B-75DEA77308DF' can't be found
What makes me strange is that I could not find the "wrong" profile.
I find a same question Distributing .app file after command line xcodebuild call. But the "archive" is invalid in xcode 4.6.
So please help me about how can I do the automating for Mac App.
Thanks!

I find it and it is the same problem like "provison not found".
What you need to do is delete the referred provision file in prom.xcodeproj/project.pbxproj.
You can find the same answers here Codesign error: Provisioning profile cannot be found after deleting expired profile

Related

Archive Failed when trying "xcodebuild archive" in terminal - Doesn't include currently selected device

Systems: xcode 13, OS Monterey 12.5
Summarize the problem: My goal is to archive an iOS xcode project from command line using the xcodebuild archive command. I have my iPhone connected and xcode recognizes this device. I am able to archive this project by selecting xcode Product/Archive in the xcode IDE but for some reason when I run the xcodebuild archive command below I get the Archive Failed error that states,"Provisioning profile "iOS Team Provisioning Profile" doesn't include the currently selected device". The currently selected device stated in the error is my computer I.D. and not the iPhone I have connected. Again, this runs fine when I archive in xcode GUI so it seems my following command in terminal is incorrect.
I tried the fix in other related stackoverflow questions but they did not resolve my specific issue.
command: xcodebuild archive -target AnalyzeSourceCode.xcworkspace \ -scheme AnalyzeSourceCode \ BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ SKIP_INSTALL=NO
I have tried various combinations of the command:
*Specifying workspace and destination:
xcodebuild -workspace AnalyzeSourceCode \
-scheme AnalyzeSourceCode \
-destination generic/platform=iOS build
*Also ran trace on devices to confirm my iPhone is recognized which it is because I see it in finder and in xcode GUI.
xcrun xctrace list devices
It seems that my xcodebuild command is not correct.
Solution found in Apple Forum: LINK: https://developer.apple.com/forums/thread/668952
The post originator (Namzak) had the same issue and the archive failure was due to not including the destination when running xcodebuild command in terminal when archiving the project.
The key to my solution was the destination line below:
-destination 'generic/platform=iOS'
Complete Command I Execute:
xcodebuild archive -scheme APP_NAME_HERE \
-configuration Release \
-destination 'generic/platform=iOS' \
-archivePath "APP_NAME_HERE.xcarchive"

Xcode 7: Xcode cannot run using the selected device

After upgrade to Xcode 7, Xcode cannot run tests on simulator.
$ xcodebuild test -sdk iphonesimulator -scheme MyProject
Build settings from command line:
SDKROOT = iphonesimulator9.0
xcodebuild: error: Failed to build project MyProject with scheme MyProject.
Reason: Xcode cannot run using the selected device.
The issue is reproduced on Travis CI and Jenkins. It's worked fine when I run xcodebuild test on a local machine.
I've gotten past this error by adding a flag like -destination 'name=iPhone 6'. It seems like xcodebuild used to pick a default destination but isn't doing that anymore. =|
I'm going to see if there is anything I can set in the build scheme to avoid hard coding a device.

xcodebuild fails through Jenkins

We have been doing CI builds through Jenkins. I did not set up Jenkins so I can't answer questions about how its set up.
We are adding a WatchKit extension. We are following these steps https://developer.apple.com/library/mac/qa/qa1814/_index.html to switch from specifing the provisioning profile to switching to automatic.
The build command fails through Jenkins, but if I run the command from the command line, it works. I think both are using the same user. The distribution certificate is in the login keychain and the system keychain.
Our command is
xcodebuild -configuration Release -target "mobile" -sdk "iphoneos8.3" -scheme "mobile" clean archive
The error we get is like this for each extension and application:
Code Sign error: No code signing identities found: No valid signing identities (i.e. certificate and private key pair) matching the team ID “XXXXXXXXXX” were found.
CodeSign error: code signing is required for product type 'App Extension' in SDK 'iOS 8.3'
Any advice how to fix or troubleshoot this error?
Try moving the certificates you required in your Keychain. Move them from Login to System
Try adding Jenkins profile management plugin & adding prov and then compile using XCBuild.
When I execute the following command via Execute Shell, I am able to run xcodebuild:
security unlock-keychain -p ${OSPASSWORD} ~/Library/Keychains/login.keychain-db && xcodebuild -scheme ${XCODE_SCHEME} -sdk ${XCODE_SDK} -archivePath \"build\" -configuration Release archive
Hope it helps.

Can't run Kiwi tests (XCTest) in xcodebuild (Xcode 6)

I'm trying to run my tests using the CLI tools. After following various guides, I came up with this command:
xcodebuild -workspace myworkspace.xcworkspace -scheme testsScheme -sdk iphonesimulator -arch i386 -configuration Debug TEST_AFTER_BUILD=YES clean build
The error I'm getting is:
The following build commands failed:
Ld /Users/<my name>/Library/Developer/Xcode/DerivedData/<project name>-gqrdtdiypfxjrbbjaqofxcjdckcg/Build/Products/Debug-iphonesimulator/<target or schema name>.xctest/<target or schema name> normal i386
I have no idea why the build fails as the error message is not very giving.
As for my pre-configuration, I've followed some guides and did the following: I've added a test-only scheme which targets my tests target (like I've seen in many guides), and also set it's executable to be the .app file (the default settings has no executable which results in an error that the app file is not found).
I'm using Cocoapods, and still not using the standard architecture (arm7, arm64) in my project (I'm dependent on a 3rd party that still hasn't upgraded, so currently my setting is $(ARCHS_STANDARD_32BIT)).
I've also checked that the "${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests" run script appears and happens last in the build phases.
Note that running the tests using CMD+U works as intended.
EDIT: Apparently, The .app file wasn't created after a clean (so removing the clean or pre-building the app worked). Nevertheless (even though I need to solve this as well). I'm now getting this error:
PhaseScriptExecution Run\ Script /Users/shay/Library/Developer/Xcode/DerivedData/<name>-gqrdtdiypfxjrbbjaqofxcjdckcg/Build/Intermediates/<name>.build/Debug-iphonesimulator/<test schema>.build/Script-48FB07F617A93C57006E5E2A.sh
I've read that might happen when the iOS simulator is opened, but it happens even if I kill it before running the script.
After sleeping on it, I solved my issue by running:
xcodebuild -workspace <name>.xcworkspace -scheme <scheme> -sdk iphonesimulator -arch i386 -configuration Debug clean build test
Where the scheme is the original one, and not a specially-created one for the tests.

xcrun doesn't embed provisioning profile into ipa

I am writing a build script for my phonegap-ios program. I am experiencing some problems during the code signing process. I use my script to build and code signing the project and generate ipa file. But the ipa failed to install to my iphone via iTunes. And I compared the ipa file which generated by my build script and the ipa file generated from Xcode organizer. The build script doesn't contain embedded.mobileprovision and resourceRules.plist. So anyone can tell me anything wrong with my build script? I have made sure paths are right. I use Xcode 4.6.3 (4H1503) and my Mac OS is 10.8.4. My build script is listed below. Thanks.
xcodebuild -project $PROJECT_NAME.xcodeproj -arch i386 -target $PROJECT_NAME -configuration Release -sdk $SDK clean build VALID_ARCHS="i386" CONFIGURATION_BUILD_DIR="$PROJECT_PATH/build"
codesign -f -v -s "$CODE_SIGN" "$PROJECT_PATH/$APP"
xcrun -log -sdk iphoneos PackageApplication -v "$PROJECT_PATH/$APP" -o "$PROJECT_PATH/build/$PROJECT_NAME.ipa" --embed "$PROFILE"
I had same problem while trying to automate my build of iOS app. Apparently xcrun in order to embed provisioning profile, requires an --sign "iPhone Distribution: ..." option to be specified on command line.

Resources