MonoTouch: Create iOS AppStore-Version from command line - ios

I want to build my ios-apps Appstore-ready directly from the command line with the mdtool from MonoTouch (Xamarin) so that Jenkins can kick in and produce the uploadable package right away.
I use the following command:
'/Applications/Xamarin Studio.app/Contents/MacOS/mdtool' -v build '--configuration:AppStore|iPhone' MyAppProject.csproj
Now, the build runs, uses my AppStore Provisioning Profile and creates the files in my bin/iPhone/AppStore - folder.
Now, according to the documentation of Xamarin, I should zip the created app-file in the bin/iPhone/AppStore and select it in xCode Application Loader like shown in the screenshot:
But the Application Loader shows every file grayed out, so there is no chance to continue.

What if you rename the .zip extension to .ipa?

I think you should not choose "Open package" but "Deliver Your App".

You can also use the xcrun ("XCode Run") command line tool to with the "PackageApplication" argument to package an ".app" into an ".ipa" and optionally specify a signing identity and provisioning profile at the same time.
Something like:
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "Ios.app" -o "Ios.ipa" --sign "[DEVELOPER_NAME]" --embed "[PROVISONING_PROFILE]”
More info on xcrun here:
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcrun.1.html

Related

Xamarin: Generate xcarchive from command line

Is there a possibility to directly generate a xcarchive file from the command line? So that you can generate an AppStore build with a CI tool like Jenkins?
With Xcode it seems you can, but I'm using Xamarin Studio on Mac. Anyway is this possible? Or can you manually create an xcarchive file with the app, dsym and plist?
On my build server I use the following commands to create an AppStore signed ipa file from an archive.
/Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool -v build "--configuration:AppStore|iPhone" -p:RssReader.iOS Apps/RssReader.sln || exit 1
# transform the archive into a .ipa package
xcrun -sdk iphoneos PackageApplication -v "${WORKSPACE}/Apps/RssReader/iOS/RssReader.iOS/bin/iPhone/AppStore/RssReader.app" -o "${WORKSPACE}/Apps/RssReader/iOS/RssReader.iOS/bin/iPhone/AppStore/RssReader-${BUILD_NUMBER}-appstore.ipa"

Create IPA with symbols using xcrun

I noticed a different when creating an .ipa file manually using xcrun than exporting it from xcode. The xcrun version doesn't have any symbols included with the .ipa.
I was wondering what's the best way to create an .ipa with symbols (no reason not to send them) manually from the command line, I'm using TeamCity CI to generate our production .ipa files.
I use the following command line to generate the IPA -
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "DerivedData/MyApp/Build/Products/Release-iphoneos/MyApp.app" -o "~/MyApp.ipa" --sign "<HIDDEN>" --embed "<HIDDEN>"
I run it after invoking xcodebuild so the Release-iphoneos folder got the latest release version of my app.
I'll answer myself -
In Xcode 7 Apple added the ability to specify export options plist file to better control the .ipa file creation.
One of the options there is <key>uploadSymbols</key> that does exactly what I need.
http://www.matrixprojects.net/p/xcodebuild-export-options-plist

Can't generate release build for Cordova iOS App

I am using Phonegap CLI 3.1 and XCode5. I want to generate the release build for iPhone Application through command line, I have valid distribution certificate and mobile provisioning profile. I want to generate the release build totally through command and don't want to use XCode GUI or Phonegap Build. I have tried too much with xcodebuild, xcrun and even corodva build command but none of them provide me the release build file (either in .app format or .ipa).
Method 1 (Use xcodebuild)
a) xcodebuild -project MyApp.xcodeproj -alltargets -sdk iphoneos7.0 PROVISIONING_PROFILE="PROFILE_UUID.mobileprovision" -configuration Release
** BUILD FAILED **
The following build commands failed:
CompileC build/MyApp.build/Release-iphoneos/MyApp.build/Objects-normal/armv7/AppDelegate.o MyApp/Classes/AppDelegate.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
CompileC build/MyApp.build/Release-iphoneos/MyApp.build/Objects-normal/armv7/MainViewController.o MyApp/Classes/MainViewController.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
CompileC build/MyApp.build/Release-iphoneos/MyApp.build/Objects-normal/armv7s/AppDelegate.o MyApp/Classes/AppDelegate.m normal armv7s objective-c com.apple.compilers.llvm.clang.1_0.compiler
(3 failures)
Method 2 (Use corodova build and xcrun to sign the app)
a) cordova build ios -release
Compiling app on platform "ios" via command "/Users/Macuser/Desktop/MyApp/platforms/ios/cordova/build" --release Platform "ios" compiled successfully.
b) xcrun -sdk iphoneos PackageApplication -v "build/Release-iphoneos/MyApp.app" -o "build/Release-iphoneos/MyApp.ipa" --sign "iPhone Distribution: NAME (ID)" --embed "PROFILE_UUID.mobileprovision"
error: Failed to read entitlements from '/tmp/iyibGn3aUv/Payload/MyApp.app
The problem is that you do not have proper schemes. When phonegap project is generated it does not contain any schemes and thus linking to the phonegap files is incorrect.
Go to the phonegap generated project in console and put 'xcodebuild -list'
in the output you will get that there is no schemes in the project.
Open generated by phonegap project in the xcode - this will generate schemes.
Now you can build this using xcodebuild(Remember to fill up the proper scheme name):
xcodebuild -scheme YOURSCHEMENAME -project MyApp.xcodeproj -alltargets -sdk iphoneos7.0 PROVISIONING_PROFILE="PROFILE_UUID.mobileprovision" -configuration Release
For continous integration this is bad solution because you have to launch the xcode GUI to generate the schemes but I did not found any other solution for this problem. If someone know how to generate scheme using command line it would be nice of him to write it down.
First, you need to create your app in iTunes Connect (This is in the member center of your iOS developer account). If you've already created your profiles and certificates, then you can select the correct one in iTunes Connect. Here is where you name your app, set a price, write a description, and upload screen shots and a large icon. Make sure you fill in all information and upload all images for your app. You will know when you are done the status of your app changes to 'Waiting for Upload".
After you've created your app successfully in iTunes Connect, to generate an .IPA file for distribution (either for the AppStore or Ad-Hoc) in Xcode you need to select your Project in the file tree (at the top of the tree). Then make sure your 'Targets' is selected to the right.
Choose 'Build Settings". Then go to the section where is says Code Signing. For 'Release', make sure that the correct iPhone Distribution identity or profile is selected.
Below 'Release' it should say 'Any iOS SDK'. Make sure that it says 'IOS Distribution' next to it.
If you have the correct certificates and profiles in the keychain, you can now in the menu at the top choose Product > Archive.
If it doesn't build, then press the run button to build your project. Xcode should say that it is archiving.
After it archive's successfully, go to the Organizer. In the menu at the top choose Window > Organizer. Now click Archives.
If your project successfully archived you will see it here. First you need to Validate your project with iTunes Connect. You will need to enter your iOS Developer login info. Xcode 5 does a pretty good job of detecting the correct profiles so you should see it in there.
If your app validates then you can then distribute either to the App Store or as an Ad-Hoc distribution. Depending on which profile you have.
This is the process for distributing apps either Native or Phonegap. It doesn't matter, I've built both.
I would suggest doing it this way, in case your app doesn't validate. Xcode will then tell you what you need to do to fix. Then once you fix everything. Create a new archive and try until it validates.

iOS Enterprise: Re-certify existing IPA with new certificate

We are enrolled in the iOS Enterprise Program. The provisioning profile used for our released apps is about to expire, so I got a new certificate and provisioning profile.
I need to re-distribute some of our apps with the new provisioning profile, without building them anew. How?
(I vaguely remember seeing a utility program that did exactly this: You choose an IPA and a provisioning profile, and it would create a new IPA using the new profile and certificate. What was the tool’s name, and where can I get it?)
In theory whoever built the last IPA in XCode should have used Archive - this creates a build you can sign to create an IPA (using XCode).
You could also try using the command line signing tool XCRun to re-sign the App bundled in your existing IPA:
http://skabber.com/package-your-ios-application-with-xcrun
OK, turns out when you know what term to google, there‘s lots of excellent resources…
They all point to xcrun. I made it work with this shell snippet, adapted from this promising build script:
APP_FILENAME=MyApp.app
BUILD_DIRECTORY=/Path/To/Target/Dir
IPA_FILENAME=MyApp.ipa
DISTRIBUTION_CERTIFICATE='iPhone Distribution'
PROVISIONING_PROFILE_PATH='/Path/To/Profile.mobileprovision'
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "$APP_FILENAME" -o "$BUILD_DIRECTORY/$IPA_FILENAME" --sign "$DISTRIBUTION_CERTIFICATE" --embed "$PROVISIONING_PROFILE_PATH"
The codesign command-line utility, included with the iOS SDK tools, will allow adding/changing the certificate and provision with which a developer built app is signed.
As hotpaw2's anwaswer states. You can also resign using the codesign tool.
The way I do it (this may not be the most efficient, but it works)
Rename the .ipa to a .zip and extract
Run The following:
/usr/bin/codesign -f -s "iPhone Distribution: Company Name" "Payload/MyApp.app"
Re-zip the Payload folder and rename to .ipa
Note: You can also use this method to edit the embedded.mobileprovisioning file! Just remember to remove the .DS_Store (rm Payload/.DS_Store) if you are using finder.
You can do manual way if you just resigning app from same account with following steps.
All this is using shell script and super easy provided you know how to use shell commands.
Rename IPA to zip
unzip this file to temp folder
Remove the old _CodeSignature folder from all targets (if you have multiple targets like main,watch, watch extn, siri, widget, message, etc)
bring all the targets prov-profiles in one folder and replace all the embedded.provisioningprofile files for each target with the new ones
remove the archived....xccent file as this is old one (optional)
code sign with the entitlements.plist created for all the entitlements if any used by the app.
Zip the folder back after code sign all okay with no errors
Rename the zip to IPA
Note: To validate the IPA before upload to apple you can just use the altool from inbuild XCode App Loader to check the new IPA.
Reference: The steps for commands is also explained here:
http://www.enterpriseios.com/forum/topic/Resigning_3rd_party_apps
If you want to get rid of manual sign use the fastlane tool as its quite simple and easy to configure.https://fastlane.tools/

Xcode4: Alternative Way to build IPAs

So with XCode4, as is kinda well known, building .IPAs can only be created used "build and archive" if only one target has "Skip Install" set to "No".
My problem is that our project contains multiple targets, that need to be shipped as .ipas at some point. Setting "Skip Install" on each on everytime i need to build an .ipa is annoying. Does anybody know of a better way, maybe using those scary "Configuration Files" I've seen mentioned somewhere? Currently, i'm using the .app from the .xarchive and build an .IPA the old way, packaging it in a Payload folder.
How about xcrun PackageApplication?
Xcode “Build and Archive” from command line
Execute xcrun from command line.
PRODUCTDIR=DerivedData/foo/Build/Products/AdHoc-iphoneos
TARGET=targetA
IDENTITY="iPhone\ Distribution:\ foo"
PROVISIONING_PROFILE="/Users/foo/Library/MobileDevice/Provisioning\ Profiles/foo.mobileprovision"
OUTDIR=out
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${PRODUCTDIR}/${TARGET}.app" -o "${OUTDIR}/${TARGET}.ipa" --sign "${IDENTITY}" --embed "${PROVISONING_PROFILE}"
How about define several targets? That should you allow to adjust each separately for your needs.

Resources