Invalid IPA when building through command line - xcode

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

Related

Signing app with xcodebuild command line with PROVISIONING_PROFILE fails

I trying to sign my app command line using Xcode.
Running xcodebuild command-line on MyApp.xcodeproj like so:
xcodebuild -project "MyApp.xcodeproj" -target "MyApp" -sdk "iphoneos" -configuration *Release* PROVISIONING_PROFILE="xxxx-xxxx-xxxx-xxxx" CODE_SIGN_IDENTITY="iPhone Developer: something.com (SOMEVALUE)"
Gives following error:
Check dependencies
Provisioning profile "iOS Team Provisioning Profile: *" doesn't include signing certificate "iPhone Developer: something.com (SOMEVALUE)".
Provisioning profile "iOS Team Provisioning Profile: *" is Xcode managed, but signing settings require a manually managed profile.
Code signing is required for product type 'Application' in SDK 'iOS 10.3'
** BUILD FAILED **
What is wrong ? What is missing in my xcodebuild command ?
How can I include the signing certificate that its asking about ?
What I tried from answer & comments below
As I understand, a dedicated distribution profile should be used with Release build. That is present in the system. I just need to know how to use it with xcodebuild command for manual signing if I can.
Executing security find-identity -p codesigning -v | grep "$CODE_SIGN_IDENTITY" gives a list of 5 signing identities ones of them clearly states as iPhone Distribution: My Company (SOME123ID).
*So, can I use the distribution profile with xcodebuild manual signing? If yes, How can I get the actual ID of a distribution profile to use with xcodebuild command?
Using PROVISIONING_PROFILE is deprecated since Xcode8. Try PROVISIONING_PROFILE_SPECIFIER instead. PROVISIONING_PROFILE_SPECIFIER="Human Readable Prov Profile Name"
It may also be necessary to turn off Xcode's Automatic Signing:
Xcode9: simply append CODE_SIGN_STYLE="Manual" to your xcodebuild command
Xcode8: sed -i '' 's/ProvisioningStyle = Automatic;/ProvisioningStyle = Manual;/' TestApp/TestApp.xcodeproj/project.pbxproj && xcodebuild ...
You can check your Xcode Version on the command-line with xcodebuild -version

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.

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.

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

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