Is there a way to re-provision an iPhone IPA file without re-compiling or using XCode? - iphone

We've created an iPhone application and provisioned the application for deployment. In XCode we've used the build & archive tool to create an IPA file that can be used for installation. When new devices are added to the profile we would like to re-provision the IPA without recompiling or re-exporting the app from XCode.
Is there any way to do this?

If you look at the detail tabs of the XCode Build Results window after your Ad Hoc build, you will notice that the last few steps include running the ProcessProductPackaging and CodeSign utilities.
If you copy those command lines (and the intervening and following steps, if any), you could manually run these commands (or from a shell script), substituting the newer mobileprovision file in the appropriate place, to create a reprovisioned ipa file without a recompile.

Related

using xcodebuild command line to put an app on the iPhone

Is this possible? How does Xcode actually deploy iPhone apps that were built into the iPhone?
Or is there another tool which I'm missing out on?
clarification: by "deploy" I mean actually install and run gdb on the iPhone like when you do run>debug
xcodebuild only builds targets, it does not run executables; there's no way for it to invoke the code that transfers an iPhone app to a device and starts the debugger.
xcodebuild is what Xcode uses under the cover the build iPhone apps. So you can definitely use it to build the app. Just cd into the directory in which your project resides and then execute xcodebuild:
cd myProjectDir
xcodebuild
This will build the project in that directory, much in the same way as if you'd hit Build from xcode.
One thing you cannot do with xcodebuild is deploy the app to the iPhone. If you want to do this I beleive the simplest way is to use Xcode. If you want to automate this I would suggest using AppleScript.
You can find out more about xcodebuild here, a page which includes the following description of xcodebuild:
Run xcodebuild from the directory
containing your project (i.e. the
directory containing the projectname.xcodeproj package). If you have multiple projects in this
directory you will need to use -project to indicate which project should be built.
By default, xcodebuild builds the first target listed in your project,
with the default build configuration. The order of the targets is a property of the project and is
the same for all users of the
project. The active target and active build configuration properties
are set for each user of the
project and can vary from user to user.

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have a manifest file listing what goes in, which limits the copy. We have our own Python script which does the copy, refreshing only the files which have changed.
I have made a Run Script Phase in Xcode to call that script, but I am having a few issues related to the Code Signing phase.
Since we use a separate manifest file, my Run Script Phase cannot specify any input/output file in the Xcode GUI: it varies depending on what is contained in directories at the time. The side effect of this is that Xcode doesn't strictly know what files will get copied (things happen "under the cover", so to speak).
The problem I have is that if I only modify resource files between builds, rebuilding my app will properly call my script, which copies the appropriate files, only Xcode won't rerun the Code Signing step, and won't re-copy my app to my device.
I found that odd, considering that my resource files are indeed listed in the <app_bundle>/_CodeSignature/CodeResources file, but it looks like Xcode determines rebuilds requirements independent of that (likely only files listed in the project file), which is understandable.
I tried playing tricks by touching my app bundle's directory, or the app's binary itself, but it doesn't quite work. Touching the app's bundle directory doesn't seem to do anything, while touching the binary will work, but NOT FOR THE CURRENT BUILD, only the subsequent one (since no input file requires recompilation, Xcode infers no new binary gets generated, but the next time, it will indeed detect that the binary has been touched, and redo both Code Signing and on).
Still, this is quite an imperfect workaround, because:
Having to build twice is error prone
My dSYM file will needlessly get regenerated
Does anyone know of any way to force the Code Signing step in Xcode (from a Run Script, or elsewhere)?
You can call codesign directly from the command line or a shell script, e.g.
codesign -f -s "iPhone Distribution" --entitlements Entitlements.xcent -vv location/MyApp.app/MyApp
Run man codesign to find out the usage.
You can discover all the internal commands run by viewing the detailed build output in Xcode. Select the Build tab, then click the little icon at the bottom left of that window pane - the one that looks like text (it is next to the warning icon). This will show the full build output in a new pane in Xcode.
I created a shell script calling codesign directly so I could re-sign an existing binary using a new certificate and provisioning profile (e.g. after updating some graphics in the binary).
This turned out to be really complicated as Xcode does some subtle stuff as part of its internal build processes (one example: Xcode embeds the provisioning profile in the resulting app binary, but in the process changes some of its values, e.g. the get-task-allow setting). That meant I had to write a tool to generate an appropriate .xcent file from the provisioning profile, depending on whether a Development/Distribution/App Store build is being done. Hopefully none of that will affect you...

Problem installing ad-hoc app on iphone: "resources have been modified."

I can install an app on my development iPhone compiled with "Debug" configuration using my Ad Hoc provisioning and everything works OK.
But when I build it using "Release" configuration, iTunes says:
The application XXX was not installed on the iPhone "YYYY" because its resources have been modified.
I've never seen this message before. Does anybody know what it means?
Thanks!
Antonio
We had the same problem during our first Beta. Someone on Windows dug in the xxx.app folder then Explorer created a Thumbs.db file inside and, boom, he got the message "The application XXX was not installed on the iPhone "YYYY" because its resources have been modified." when he tried to install.
He had to remove the app from iTunes, deleted all the Thumbs.db from xxx.app and then it worked.
We finally got rid of the problem. We were trying to include an image for iTunes after creating the build, but when we used this method (http://iosdevelopertips.com/xcode/itunes-icon-for-ad-hoc-distributions.html) everything went smoothly.
Just in case it helps someone: In my case, I copied the .app to a network drive, then to my Win7 computer before dragging into iTunes - then it did not work. When I zipped the .app first before copying, and then unzipped it on the other end - it worked. Of course, I have no real idea why....
Your debug configuration and your release configuration have some important differences, and release is a lot closer to what ad-hoc should look like. So you first need to duplicate the release configuration and make and call your copy "Ad-Hoc", and make sure you use your ad-hoc provisioning profile with it. Then you need to create a new entitlements file. The new version of Xcode has a cool feature where you can build and archive your app into an ipa file that includes your provisioning profile.
How to do all of this is explained here: http://www.tuaw.com/2010/05/23/devsugar-a-better-way-to-share-ad-hoc-builds/
In those instructions, when it tells you to make the entitlements plist file, it says to uncheck get-task-allow in the plist file. When I created the entitlements file, there wasn't a get-task-allow row at all, so I created one, set the type to boolean, and left it unchecked. It worked great for me.
The best solution to avoid wierdness like this is to create an IPA file. A good step-by-step guide to creating an IPA target in XCode is here:
http://idotcomllc.wordpress.com/2009/05/26/how-to-build-a-ipa-file-from-xcode/
It starts out with an introductory project so search for "Aggregate" to find the point where it starts telling you how to create a new IPA target for build.
I directly upload the app to a server where the windows can also visit. Then compress it in Windows.
I had it, did a clean build and never saw it again.
Incomplete ipa/zip archives (received at the installation end) were the cause for us.
I had this problem using a run script to cp -R the .app file to the Payload folder, for some reason when the script copied the file it modified it somehow, if I used finder and manually copied the .app file into the payload folder and manually zipped the .ipa file it worked fine. I tested it several times using codesign -v to verify the .app file. it always through the error after a build and the run script. but no error when I would copy the file manually.
For me the issue was the .Double files being added to every directory on a shared network drive. We are primarily a Windows environment, and the Mac was saving .Double file on the drive, in every directory.
Literally, to fix the issue referenced above, I simply deleted the .Double files in every directory (of the app being copied to iTunes) and it fixed it.
Hope this helps someone!
I was tasked to test some apps and for some reason was the only one on my team getting this this error. I am working on an XP. All the apps we are testing use the same provisioning file yet some would sync while others would not. Not sure what fixed it but I did go into my *My Music\iTunes\iTunes Media\Mobile Applications* folder, deleted the existing .ipa file for the app I was trying to sync and it seemed to sync fine after. It might not be the answer to your problem but give it a try.
If you work with asstes on a Mac, or have versioned content, I had the same problem with .DS_Store files and hidden .git folders. Once deleted from assets, problem gone. It might be an issue with hidden files.

Can Xcode include application resource files that are generated during the build process?

I have a bunch of content files for my iPhone app that I generate via shell script. It takes way too long to be a part of the Xcode build process, so I run it periodically.
I don't want to have to continually add these files to my Xcode project in order to get them included my app resources folder. Is there a way to get Xcode to copy the contents of a folder into the app resources at build time? (It'd be a bonus if I could specify other locations, such as the approot documents folder.)
I tried adding a new 'Copy Files Build Phase' to my target, but that didn't seem to work. This seems like a common problem, but I couldn't find anything about it here.
-- Edit (What I did)
Per Jasarien and cdespinosa's suggestions, I did the following in a build script. I decided not to copy to the destination, because that would only work when using the simulator, I don't think that'll work when deploying to a device.
cp -rf "$PROJECT_DIR/mystuff" "$CONFIGURATION_BUILD_DIR/$CONTENTS_FOLDER_PATH/"
-- Edit 2
This doesn't appear to get files onto my iPhone. Any ideas?
You can setup a Run Script build phase in your app's target. Write the script so that it copies the resources into the app bundle.
This is the path i use for output:
${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}
Just copy your files in that directory, it's the bundle (simulator or device).
You can also take a look at my answer here : how to set up a Xcode build rule with a variable output file list?

How can I install a .ipa file to my iPhone simulator

I have an iphone simulator running on my Mac.
I have a .ipa file, can you please tell me how can I install it on the simulator?
You can't. If it was downloaded via the iTunes store it was built for a different processor and won't work in the simulator.
I found an .ipa file that I wanted using iTunes and copied it over to my desktop.
After that I changed the extension to .zip and extracted it.
Next I found the Payload folder and moved the application inside to my desktop.
Finally I moved that application to my iPhone simulators applications folder found at:
HD
> Applications
> Xcode.app (right click - Show Package Contents)
> Contents
> Developer
> Platforms
> iPhoneSimulator.platform
> SDKs
> iPhoneSimulator6.0.sdk
> Applications
(Note: Some apps crash more often than others.)
In Xcode 6+ and iOS8+ you can do the simple steps below
Paste .app file on desktop.
Open terminal and paste the commands below:
cd desktop
xcrun simctl install booted xyz.app
Open iPhone simulator and click on app and use
For versions below iOS 8, do the following simple steps.
Note: You'll want to make sure that your app is built for all architectures, the Simulator is x386 in the Build Settings and Build Active Architecture Only set to No.
Path: Library->Application Support->iPhone Simulator->7.1 (or another version if you need it)->Applications
Create a new folder with the name of the app
Go inside the folder and place the .app file here.
Update for Xcode 9.4.1+
Hope my answer is getting seen down here as this took me a while to figure out but I just got it working.
First of all you need to build and run the App on your simulator. Then you open the Activity Monitor. Double click the name of your App to find its content.
In the next screen open the Open Files and Ports tab and find the line with MyAppName.app/MyAppName.
Copy the link but make sure to stop at the MyAppName.app. Do not copy the path following it.
Control click onto the finder icon and select Go to folder.
]
Paste the path and click enter. You will see your MyAppName.app file.
Copy it to the Desktop and zip it. Move it to your desired 2nd computer and unzip the file. Build a random project to have a simulator open.
Lastly: Literally drag and drop the App from your Desktop into your Simulator. You will see the install and the App opens and does not crash.
You cannot run an ipa file in the simulator because the ipa file is compiled for a phone's ARM architecture, not the simulator's x86 architecture.
However, you can extract an app installed in a local simulator, send it to someone else, and have them copy it to the simulator on their machine.
In terminal, type:
open ~/Library/Application\ Support/iPhone\ Simulator/*/Applications
This will open all the applications folders of all the simulators you have installed. Each of the applications will be in a folder with a random hexadecimal name. You can work out which is your application by looking inside each of them. Once you have found out which one you want, right click it and choose "Compress ..." and it will make a zip file that you can easily copy to another computer and unzip to a similar location.
UPDATE: For Xcode 8.0+ you need to follow below Steps:
Download application from iTunes
Select downloaded app, right click show in finder
Copy .ipa file to Desktop, rename it to .zip file
Extract that .zip file and you will get directory with application name
Check that directory you will find app file in Payload folder, copy this app file
Go to ~/Library/Developer/CoreSimulator/Devices
FYI: Library folder is hidden by default in mac, you can see hidden file using below command.
defaults write com.apple.finder AppleShowAllFiles YES;
killall Finder /System/Library/CoreServices/Finder.app
Now here you'll see many directories with long hexadecimal names, these all are simulators.
To find your desired simulator, sort these directories using "Arranged By > Date Modified".
Select that simulator file and go to below location.
<HEXADECIMAL-SIMULATOR-STRING>/data/Containers/Bundle/Application/
Create new folder name with <download-app-name> and paste app file in that folder
Open Terminal and run below command to install this application
xcrun simctl install booted <APP_FILE_PATH>
Example <APP_FILE_PATH> will be looks like below:
~/Library/Developer/CoreSimulator/Devices/<HEXADECIMAL-SIMULATOR-STRING>/data/Containers/Bundle/Application/<APP_NAME>
First of all, IPAs usually only have ARM slices because the App Store does not currently accept Simulator slices in uploads.
Secondly, as of Xcode 8.3 you can drag & drop a .app bundle into the Simulator window and it will be installed. You can find the app in your build products directory ~/Library/Developer/Xcode/DerivedData/projectname-xyzzyabcdefg/Build/Products/Debug-iphonesimulator if you want to save it or distribute it to other people.
To install from the command line use xcrun simctl install <device> <path>.
device can be the device UUID, its name, or booted which means the currently booted device.
For Xcode 10, here's an easy way that worked for me for a debug IPA (development profiles)
Unzip the IPA to get the Payload folder.
Within the Payload folder is the app executable.
Drag and drop the app to an open simulator. (You might see a green add button when you drag it over the simulator)
It should install that app on that simulator.
You can run the application file of project in simulator - not .ipa file.
You can get it from:
Libraries-->Applicationsupport-->iphone simulator-->4.3(its ur simulator version)-->applications-->then u can see many files like 0CD04F.... find out your application file through open it.
You can copy the file to your system(which system simulator u need run ) location Libraries-->Applicationsupport-->iphone simulator-->4.3(its your simulator version)-->applications-->
Then open the simulator 4.3 (its your simulator version where you pasted). You can see the application installed there.
Getting from other people:
Please tell them to find out Libraries-->Applicationsupport-->iphone simulator-->4.3(its ur simulator version)-->applications-->then you can see many files like 0CD04F.... from their system and receive that file from them.
After they have got the file, please copy and paste the file in to your system `Libraries-->Applicationsupport-->iphone simulator-->4.3(its your simulator version)-->applications-->(paste the file here).
Then you can see the app is installed in your system simulator and you can run it after clicking the file.
Copy From Here:
- Run the application in the Xcode.
- Select Finder go to Go and click on select Library Library/Application Support/iPhone Simulator/7.0.3-64/Applications
- Select 32 bit folder Copy your application.
Paste To Here:
- /Applications/Xcode-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhone Simulator. SDK/Applications
- Paste here and run the simulator.
With Xcode 6:
It's very possible to build and install on a simulator.
I did it by copying the debug build configuration (I called it SimRelease for my example below) in the project settings. I changed the architectures to i386 and x86_64 (not sure how necessary this was), but key difference to change between the copied build configuration is build for active architecture set to NO. After that a couple simple command line tools will do the rest!
xcodebuild -scheme YOUR_SCHEME -configuration SimRelease -sdk iphonesimulator8.1
Depending on where you have your DerivedData set you need to go find the outputted .app folder. Once you've found it you can simply install it on any simulator device. To find the device UUID's open Xcode and go to Window->Devices you'll see the list of the device instances and you can grab the UUID's. For a trivial script you could grab all of them from: ~/Library/Developer/CoreSimulator/Devices/ and install on every device.
From there the simple command to install on a device is:
xcrun simctl install DEVICE_ID APP_FOLDER_LOCATION
Here's a simple shell script to take the app and install it on every device:
app_dir=$1
current_dir=$(pwd)
cd ~/Library/Developer/CoreSimulator/Devices/
devices=$(ls -d */)
cd "$current_dir"
for device in $devices
do
device_id=${device%/}
xcrun simctl install "$device_id" "$app_dir"
done
Hope this helps! Took me a while to figure out the best way to do it.
Step to run in different simulator without any code repo :-
First create a .app by building your project(under project folder in Xcode) and paste it in a appropriate location (See pic for more clarity)
Download Xcode
Create a demo project and Start simulator in which you want to run the app.
Copy the .app file in particular location(ex :- Desktop).
cd Desktop and Run the command (xcrun simctl install booted appName.app),
App will be installed in the particular booted simulator.
Tested on iPod touch (7th generation) Simulator 13 (iOS 15.0)
Xcode and Xcode Command Line tools are already installed
Since we have an .ipa file, we can get the .app file from it
Rename .ipa file as .zip and extract the contents
Once the zip file is extracted, we can find the Payload folder which contains App_Name.app file
Open Terminal or iTerm2 app
Navigate to the folder which contains .app file
To list all iOS connected devices & iPhone simulators -> Also shows the UDID of all devices
xcrun xctrace list devices
Boot the simulator
xcrun simctl boot <UDID>
Launch the simulator
open -a simulator
Install the .app file
xcrun simctl install booted <App_Name>.app
Just drag and drop .app file to simulator it will install app automatically.
I have checked in iPhone simulator 13(iOS 15.4)