XCode: iPhone target dependency on Mac OS X target - iphone

I'm building an iPhone application, and I want to run a custom built-on-the-fly Mac OS X command-line utility during the build phase of the iPhone target. I set up the command-line utility as a dependent target of the iPhone target, but it won’t build, telling me:
target specifies product type ‘com.apple.product-type.tool’, but there’s no such product type for the ‘iphoneos’ platform
Is there any way to do this correctly?
Thanks!

Have you tried adding a run script build phase? From there, you should be able to execute any other scripts you wish, including compiling other tools or projects.
Right click on the target and Add New Build Phase.

Related

Run A multiplatform xcode project

I have a project that has two targets one for iOS and other OSX. When I run the project it builds successfully. But Its nit running.I want to run this ample project in any of the platform. How can I do this.
This won't work, because iOS and OS X are based on different frameworks.iOS needs UIKit. But if you compile a project for Mac that contains UIKit, you will get an error. You cant just set Xcode to compile for Mac if you use the wrong 'base classes'.
Just create 2 Xcode projects that contain all the classes you want to use, one for OS X, one for iOS.

iPhone + OSX targets on the same project

I created a project with two targets, one for iPhone and another for Mac OsX. They both build and run well when I build them the first time (I built the OsX target first then iPhone target next).
However, if I build the iPhone target and switch back to OsX target, the OsX target now thinks that it uses the iPhone SDK rather than it's own mac OsX SDK, and doesn't compile anymore (can't find the OSX SDK header files).
My build settings of the project and targets are setup correctly and the ".pbxproj" file is not changed in the process of switching targets. But I tracked down the problem to the ".pbxuser" file, specifically in the parameter "activeSDKPreference =".
Basically when I switch to iPhone target this parameter gets changed from macosx10.6 to iphonesimulator4.0, but when I switch back to OsX target it stays on iphonesimulator4.0. The only way to get it to work again is to close the project, manually change that param to macosx10.6, and reopen the project. This would solve it until I switch to iPhone again.
Is it a bug in XCode? anyone has a solution or a work around?
The same question is asked and answered at http://lists.apple.com/archives/xcode-users/2010/Oct/msg00132.html
It says there: "you can Opt-Click your "Overview" combo box ([in the] Xcode Project [window], in the toolbar). You should see a more complete list of Active SDKs; pick an explicit OSX SDK".
it is a bug in xCode, so you use the latest version of xCode
when you build this it set all your target. you can solve this by clean all target than build it. you wil find this in xcode build manu >> clean all target. than build this. it will work.

Unit tests only run automatically when active SDK is "simulator"?

I have followed the instructions Apple publishes for unit testing applications on iPhone and things work great when I set the active SDK to "iPhone Simulator". I have it configured to always build and run my tests as part of building the application itself.
Apple implies (by omission) that this should work all of the time, but the tests are skipped when I set the active SDK to "iPhone Device". I am also linking with OCMock, and instead of a failing test, this warning is in the build log:
ld: warning: in .../build/Debug-iphoneos/OCMock.framework/OCMock, missing required architecture arm in file
It's very nice to make the unit test bundle a dependency of the main application, so these tests run at every build, but its utility is greatly diminished if it doesn't work during device builds. Is this a known, but undocumented, limitation?
As Kristopher commented, this is just the way XCode behaves. The Run Script step at the end of your Unit Test target will actually run the built target when the SDK is set to Simulator, but if you look at the build output it will just balk when building against the Device SDK.
Basically, build your LogicTests against the Simulator SDK and build your ApplicationTests against the Device SDK. It's a pain, but that's just the way it works.
Also, if you want to get OCMock working for ARM (which you will likely want for Application Tests that run on the actual device), I believe their OCMock lib target is "fat"/Universal by default. That is, it will include both i386 code and arm code within the same library. You'll have the best results if you check out their repository and build it yourself.

Running Xcode iPhone unit tests with Cruise Control

When using Cruise Control to build an iPhone XCode project with Unit Tests, an error of "Code Sign error: a valid provisioning profile matching the application's Identifier 'com.yourcompany.Calculator' could not be found" is generated. This isn't encountered when run through XCode? Is Cruise Control trying to launch the app rather than just build it? Any suggestions?
I don't know for sure if xcodebuild properly runs the code signing tool, but it sounds to me that you'll need to change your build process to use that tool (codesign).
I'm not sure if it's a pre-build or post-build task.
codesign man page: http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/codesign.1.html
According to this this SO post, you may be able to get around this by telling xcodebuild to assume the target is the iPhone Simulator instead of the actual iPhone (with the -target command line option)
The problem was caused by the addition of the Unit Test Bundle to the project. To ensure that tests were built and run along with the main project, I had dragged the Unit Tests target into the main project Target.
By default, it had assigned the Unit Test Bundle to be built against the iPhone Device 3.1.2 SDK rather than the simulator.
Also, the Unit Test Bundle had an auto-generated .plist file which contained the default Bundle Identifier of com.yourcompany...etc.
So despite specifying a target which I knew had a default SDK of the iPhone Simulator 3.1.2, the inclusion of the Unit Test Bundle caused the error to keep appearing.
Selecting 'Get Info' for the Unit Test bundle, select the Build tab and set the Base SDK to iPhone Simulator 3.1.2 and all will be well.

How do I automatically run my iphone app after building it?

I'm using google unit testing code.
I'm building it quite nicely with xcodebuild on the command line. Now I want to run it (preferably on attached Device but simulator would also work) and catch all the feedback from the tests.
But I can't find out how to run it. Any ideas?
Jeff Haynie's iphonesim project on Github looks like it could work. I had trouble building 27812bb4b (make failed on a warning in nsprintf.m), but that may just be me using a pre-release OS and SDK. See also this related question.
If you followed the instructions from the Google page (creating the target, adding the test files to the target) and you have an iPhone SDK certificate (you need it to upload apps to the device) you can just change the Active SDK to your device (upper left corner combo in XCode)
If you don't have a certificate, you need to apply to the SDK program.
The only iPhone simulator and debugger I'm aware of comes with the iPhone SDK. In order to use the iPhone SDK you need to have an Intel-based mac with OS 10.5 Leopard installed, in which case you might as well be programming/compiling in XCode instead of using the command line.
There has to be some misunderstanding here. What exactly do you want to run from the command line? The test suite? If so, the test suite should be a separate target, so that all you have to do is build it, for example like this:
xcodebuild -target UnitTests -sdk iphonesimulator2.2.1 -configuration Debug
If you have the testing target configured correctly, it will run the RunIPhoneUnitTest.sh shipped with the Google Toolbox and the script will run all your tests.