xcrun doesn't embed provisioning profile into ipa - xcode

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.

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"

the ipa created by command-line is smaller than create by xcode6,why?

The command-line script:
xcodebuild
xcodebuild -verbose ARCHS="armv7 arm64" VALID_ARCHS="armv7 armv7s arm64" ONLY_ACTIVE_ARCH=NO DEPLOYMENT_POSTPROCESSING=YES \
-configuration Release PROVISIONING_PROFILE="${profilename}" CODE_SIGN_IDENTITY="${codesign}" \
clean build OBJROOT=${distDir}/Obj.root SYMROOT=${distDir}/Sym.root
# ipa
appname=$(basename ${distDir}/Sym.root/Release-iphoneos/*.app*)
target_name=$(echo $appname | awk -F. '{print $1}')
mkdir -p $project_path/package/Products
xcrun -sdk iphoneos PackageApplication -v "${distDir}/Sym.root/Release-iphoneos/${target_name}.app" -o "$project_path/package/Products/${ipaName}" --embed "${profile}"
And the result is: command-line's ipa is 8M smaller than xcode one, Why?
Sadly, ipa files generated from the command line are not identical to those from the Xcode app.
As you already noted, the command line one has a few missing items.
In addition to Symbols, if your app is written in Swift, there will be a SwiftSupport folder with a few libraries in the ipa generated by the Xcode app but not the command line one. Similarly, if your app includes a Watch App, there will be a missing WatchKitSupport folder.
Some of these missing items will be problematic when it comes to uploading an ipa to iTunes Connect. You will find numerous posts about these issues and the workarounds being adopted - but it all boils down to this issue of command line builds lacking all the required content for app distribution.
Luckily, the new version of xcodebuild within Xcode 7 has a solution to most of these issues but is not yet documented. Here's some details on it if you are interested.

xcodebuild: build Mac OS app

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

Invalid IPA when building through command line

I am currently having issues creating an IPA file through the xcode command line tool (xcodebuild and xcrun). I first run the following:
xcodebuild -scheme scheme -sdk iphoneOS6.0 -arch armv7 -configuration config clean build#
where scheme and config is the relevant scheme and configuration
I then run
xcrun -sdk iphoneos PackageApplication -v appPath -o ipaPath -sign codesignature
where appPath and ipaPath are paths to the app and ipa and the codesignature what I am signing the ipa with. I have also tried embedding the provisioning profile
The process produces an ipa file however when I try to drag it into itunes it tells me that it is not a valid IPA. I have also tried this process through ad hoc distribution process via Archive in xcode and managed to create a valid IPA, however as I am trying to automate the process this isn't really what I want.
Any thoughts why the IPA would be invalid?
Thanks
You've forgotten to --embed your provisioning profile.
I do something like this
xcrun -sdk iphoneos PackageApplication -v -o `pwd`/out.ipa --sign "iPhone Distribution: Company Name (ID)" --embed /path/to/mobileprovision

CODE_SIGN_IDENTITY parameter for xcodebuild (Xcode 4)

I'm using xcodebuild utility shipped with Xcode 3 to automate my builds under Hudson. The command looks like it follows:
xcodebuild -project Project.xcodeproj -target Target -configuration Release -sdk iphoneos CODE_SIGN_IDENTITY[sdk=iphoneos*]="iPhone Distribution:XXXXXX"
I'm trying to use the same command for Xcode 4 but it seems that xcodebuild just ignores CODE_SIGN_IDENTITY parameter and signs with the provisioning profile which is selected for the target in Xcode.
It's a quite crucial for me since I have to sign build with 3-4 different profiles. It works OK with Xcode 3 but doesn't work with Xcode 4.
Any idea how to solve this problem?
A newer xcodebuild now allows settings to be specified.
Taken from developer.apple.com:
xcodebuild [-project projectname] [-target targetname ...]
[-configuration configurationname] [-sdk [sdkfullpath | sdkname]]
[buildaction ...] [setting=value ...] [-userdefault=value ...]
I also found this resource for explaining the available settings
CODE_SIGN_IDENTITY (Code Signing Identity)
Description: Identifier. Specifies the name of a code signing identity.
Example value: iPhone Developer
However, PROVISIONING_PROFILE is missing from the index of available commands.
The command I finally used specified "CODE_SIGN_IDENTITY" & "PROVISIONING_PROFILE" settings.
xcodebuild -sdk <iphoneos> -target <target_name> -configuration <Debug> CODE_SIGN_IDENTITY="iPhone Developer: Mister Smith" PROVISIONING_PROFILE="XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX"
I had following problem:
Our developers used the 'iPhone Development' signing identity, but I needed to use the 'iPhone Distribution' signing identity for our automated integration system.
So I added the line:
codesign -f --sign "iPhone Distribution: XXXXXXX" ${PATH_TO_APP}
between the xcodebuild and the xcrun commands to swap the code signing identities (see the -f flag).
As far as I know in Xcode 4 signing is done with xcrun tool:
/usr/bin/xcrun -sdk "iphoneos" PackageApplication -v "myapp.app" -o "myapp.ipa" --sign "iPhone Developer: XXXXX" --embed "XXXXX.mobileprovisioning"
It is a bit uncomfortable to use because you must specify both your identity and mobileprovisioning file. Especially uncomfortable if you use last one from ~/Library/MobileDevice/Provisioning Profiles/ directory because its name is changed every time provisioning profiles are updated automatically from Provisioning Portal.
Just use CODE_SIGN_IDENTITY="iPhone Distribution:XXXXXX" with Xcode 4 (without [sdk=iphoneos*])
xcodebuild -project Project.xcodeproj -target Target -configuration Release -sdk iphoneos CODE_SIGN_IDENTITY="iPhone Distribution:XXXXXX"
I found a great workaround for building with jenkins.
Firstly, before setting up a job, download a jenkins plugin called:
Parameterized Trigger Plugin
https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin
Once you do that, create your job and while creating the job, select the
'This build is parameterized' checkbox
Create a String Parameter. I call mine CODE_SIGN_IDENTITY.
So the name field in the String Parameter should be:
Name: CODE_SIGN_IDENTITY
Default Value: iPhone Developer: XXX XXXXX
Description: Whatever you want to put there
Then in your Xcode Plugin, find the 'Custom xcodebuild arguments' field.
In the Custom xcodebuild arguments field, place the following value:
CODE_SIGN_IDENTITY=${CODE_SIGN_IDENTITY}
Finish setting up your job and you should be all set!
This will bypass the white space issue. The plugin is a life saver as it works wonderfully and you can customize your build with other parameters.

Resources