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

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.

Related

Can I debug directly on an iPhone-5 (armv7s) iOS App built for only armv6 and armv7?

Our iOS app relies on a commercial third-party static-lib currently only available for armv6+armv7. For this reason, I can't build our app for armv7s. Only armv6+armv7+simulator.
Our builds are deployed for and run on the iPhone-5 without a problem - it runs armv7 code.
However, I cannot find a way to debug directly on the iPhone 5. When I connect the iPhone-5 and try to build for debugging, I get linker errors like this:
"No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=armv7s, VALID_ARCHS=armv7)."
Initially,I thought that maybe my "Build only active architecture" setting for debug configuration caused Xcode not to try to build for armv7 when the iPhone-5 (armv7s) was connected.
But when I set this to "NO" (have Xcode build for ALL SUPPORTED ARCHITECTURES all the time) I get a whole other bunch of build errors (excerpt below --- we have many targets and each emits similar errors).
=== BUILD NATIVE TARGET ASPCommon OF PROJECT ASPCommon WITH CONFIGURATION Debug ===
Check dependencies
No architectures to compile for (ARCHS=i386, VALID_ARCHS=armv7).
** BUILD FAILED **
The following build commands failed:
Check dependencies
(1 failure)
Command /bin/sh failed with exit code 65
This target has NO dependencies, it only builds against iOS SDK frameworks, and builds fine when any device other than iPad 4/iPhone 5 is connected.
Finally my question: Is it at all possible to directly debug armv7 code on armv7s device? If it is possible, when Am I doing wrong in my build settings to break this?
Thanks!
Short answer: No. I believe what you are attempting to do just isn't possible! The third party static lib needs to be rebuilt for armv7s. Keep hounding them until they update their library.
Oh, I forgot I posted this question…
Eventually I was able to debug on all iOS devices, as the source of the problem was neither in the armv7-only library, or my project/target settings.
The problem was in an iOS Xcode Template I was using to create iOS "Framework" targets. (an old version of iOS Universal framework from Karl Stenerud).
Our code-base is big, and many of its main blocks serve MacOS and iOS versions of the application, plus we want to encapsulate these main blocks as "SDK"s, including library, header, resources and documentation. So --- we've been using Framework targets for this. Since there's no internal "Framework" target template for iOS - we used a 3rd-party template.
This template users build-scripts, that had a bug, that omitted platforms from the build in certain situation, hence causing our build errors, and inability to debug.
Last word --- an update of the template removed the issue.

Can't build iOS/iPhone app as anything other than i386

I am completely new to the iOS/iPhone/XCode world, so if you guess is between something rather complex and something so simple that everyone should know, I'd go with the simple answer. :-)
Okay, so I have inherited an iPhone project that we had outsourced to another company. My only objective right now is to be able to build the dang thing. I set up XCode 4.2 and installed the proper SDKs. I loaded up the project and everything seems good to this point. However, when I build, I get errors from what I believe to be the linking stage of the build. I'm not entirely sure because the statuses change quickly when building. The error I get is the following:
From what I have been able to find online, it seems that one of the libraries I am using was not compiled for the i386 platform. To start, this doesn't make sense to me because the libraries that I am using (where these errors are coming from) are currently included as sub-projects and produce .a files which I thought were arch-independent (am I wrong here??). Also, I can't find anywhere in the project where I've instructed XCode to build to an i386 architecture. This is what I've done so far:
Made sure that the file in which these errors arose was included into the "Compile Sources" section of the Build Phase tab (the .m file)
Set my architectures to armv6 and armv7 and set the Build Active Architecture Only to no. (See images below)
Main Project Config
Sub-Project Config
Event when I build using the release configuration, I still get this error and I'm not sure why. Everything that I am looking at in my build config seems to indicate that I should be building everything in an arm architecture.
You are getting errors because you messed with the architecture settings. You should not fix those towards ARM code but allow i386 as well.
Right now, one of more of your (sub)-projects build ARM code only, resulting into a linker error once you try to build a simulator version. That is happening because your Architecture settings are not as they should be.
Note your setting for Any iOS SDK, that one is incorrect as it builds only ARM code. Remove those settings entirely by using the backspace key on your keyboard after selecting that specific setting (single-click).
And this is how it should be:
$(ARCHS_STANDARD_32_BIT) resolves to ARMV7 when building device specific code and i386 when building simulator specific code. Including ARMV6 code as per my screenshot is only needed if you plan to serve the results to older iOS devices (iPhone 3G and below).
Once those settings are active in all (sub)-projects, everything should work smoothly.
For creating a universal library out of a project, useful if you plan to distribute a static library to other developers, use LIPO.
Example:
lipo input_library_1.a input_library_2.a -create -ouput output_library.a
Lets say input_library_1 was i386 specific (simulator) and input_library_2 was ARM specific (device), this will join them into a universal version usable for both simulator and device.
It seems like you have been trying to link to static library built for devices(armv6 or armv7). When your building for the simulator the architecture will be i386. So you getting all these nasty linking errors. Solution is to include the library compiled for simulator as well in your project.

Building XMLRPC.framework: Wrong Architecture?

it's me again with my iOS trouble. I've finally managed to build the master branch of this XML-RPC framework https://github.com/eczarny/xmlrpc which produced an XMLRPC.framework for me. I managed to include that framework in my iOS project, all good, but when I build it...
ld: warning: ignoring file /Users/kovshenin/Library/Developer/Xcode/DerivedData/XMLRPC-emidbddzjlofthfgowywcfscewgd/Build/Products/Development/XMLRPC.framework/XMLRPC,
file was built for unsupported file format which is not the architecture being linked (i386)
So I went back to the XMLRPC project and tried to select different Base SDKs and Architectures for the target, but with no luck, seems like it's only building it for 64-bit Intel. Even tried the iOS SDK which gives me a "The selected run destination is not valid for this action." error.
Sorry again for my "newbish" talk, but the official dev forums can't seem to help me out. Thanks!
P.S. I'm using Xcode 4.
Architecture is related to the processor on which you are running your code. If you are building for the simulator, then you are building for your Mac, which is Intel, i386. If you are building for a physical iOS device, then you are building for arm6 or arm7, depending on how new the devices are. Fourth generation iPhone 4 and iPad were the first arm7 devices.
As far as setting the build settings, I'd recommend taking a look at the build settings. In Xcode. Here's a screenshot:
Click on your project, then on your build. Under the architectures section, you can configure your architectures as necessary. You should note though, that the original developer would have to have built it for the simulator as well as the device, or you won't be able to run it on the simulator.
It looks as though the library may not fat meaning it'll only build for the device, and not for the simulator. Connect your device and select it in the drop down, then build again and see if the error disappears.

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.