Setting PRODUCT_NAME on command line causes test failure - ios

In my main target I have a user defined build setting CI_PRODUCT_NAME. It is set as part of my CI build. This is used to set the product name of the target's output by setting the Product name build setting to ${CI_PRODUCT_NAME}
This all works fine and other build settings I've defined all work as expected. The issue is the tests don't run with the following command:
xcodebuild -workspace workspace.xcworkspace -scheme scheme -configuration Debug CI_PRODUCT_NAME=test_product clean test
At first I received a linker error telling me my main target could not be found, this was due to the BUNDLE_LOADER value now not matching, so I updated it by adding a user defined build setting on my test target of CI_PRODUCT_NAME and setting the BUNDLE_LOADER value to:
$(BUILT_PRODUCTS_DIR)/${CI_PRODUCT_NAME}.app/${CI_PRODUCT_NAME}
The original linker error has gone but now I am receiving:
The test bundle at DerivedData/Scheme-edjkzeakmzewtyckdurvlrjvvxrs/Build/Products/Debug-iphonesimulator/SchemeTests.xctest could not be loaded because a link error occurred. It is likely that dyld cannot locate a framework framework or library that the the test bundle was linked against, possibly because the framework or library had an incorrect install path at link time.
I have tried a few things, it seems if I set the value of CI_PRODUCT_NAME on my main target in the xcode project to match the value passed in the command line the tests work. The tests also work when the values match in xcode and they are run through xcode.
It seems as if the CI_PRODUCT_NAME value passed on the command line is being ignore for the main target at one of the build stages, but there is no indication whats going wrong until I receive the above error

Related

xctool build failure: Test bundle not found under `Debug-iphonesimulator`

I'm experiencing failures while running xctool build. My command is as follows:
xctool clean build run-tests -only 'MyApp KIF Tests' -workspace MyApp.xcworkspace/ -scheme 'Debug' -destination "platform=iOS Simulator,name=iPhone 6,OS=latest" -sdk iphonesimulator -reporter junit -reporter plain
The build fails with the following error:
Failed to query the list of test cases in the test bundle: Test bundle not found at: /Users/myusername/Library/Developer/Xcode/DerivedData/MyApp-blbvnisblktossbxwcmnxafkngts/Build/Products/Debug-iphonesimulator/MyApp KIF Tests.xctest
I looked up the MyApp KIF Tests.xctest in the path specified in the error message, and indeed I couldn't find that file. However, this file does exist under a different path:
/Users/myusername/Library/Developer/Xcode/DerivedData/MyApp-blbvnisblktossbxwcmnxafkngts/Build/Products/Debug-iphoneos/MyApp KIF Tests.xctest
The only difference between these two paths is that one is under Debug-iphonesimulator, and the other is under Debug-iphoneos.
I also noticed that under target -> Build Settings -> Build Locations -> Per-configuration Build Products Path -> Debug, the value is $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME), which was evaluating to build/OktaVerify.build/Debug-iphoneos. So the first question is: why does $(EFFECTIVE_PLATFORM_NAME) evaluate to Debug-iphoneos? What config do I need to change to make it evaluate to Debug-iphonesimulator so that xctool can find it?
Next, I hardcoded the value of $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) to Debug-iphonesimulator, wishing to see it working. However, I got the same error. My second question is, why does the xctest file appear under Debug-iphoneos folder even the build products path specifies Debug-iphonesimulator? What setting is specifying Debug-iphoneos?
Environment is Xcode 7.2 and xctool version 0.2.8.
I solved the issue by removing "-sdk iphonesimulator" from the xctool command. This way it'll automatically choose the appropriate sdk depending on the target type.

Objective-C Warning RunUnitTests is obsolete. Xcode 7

I am getting this warning in Objective-C:
RunUnitTests is obsolete. To run unit tests for your target, use the Test scheme action in the Xcode IDE and the test action in xcodebuild.
I did some googling around and found a solution to add TEST_AFTER_BUILD and set it to YES in User-Defined settings. After doing this the warning is still there. What am I doing wrong?
You need to delete the Run Script build phase that invokes RunUnitTests from your unit test bundle target, as suggested by the Xcode info message when it tries to build your unit test bundle.
This is the offending Run Script build phase, likely stuck there by a previous version of Xcode:

Using xcodebuild and a Today Extension I get a PBXCp error

I'm using UI-Screen-Shooter to compile my app for screenshots. After I added a Today Extension the compilation won't finish due to not finding the AppExtension.appex directory. The directory is there but under a different name than xcodebuild is expecting. It is called app.appex and Xcode is looking for PhotoMind Upcoming.appex.
It fails with this PBXCp error:
/tmp/screen_shooter/PhotoMind Upcoming.appex: No such file or directory
How would tell xcodebuild that it is called app.appex instead of the name it is looking for?
I didn't find how to change the path of the Extension in Xcode build, but I was able to get UI-Screen-Shooter to build and run my app by checking the Copy only when installing box in the Build Phases settings.
Select "Extension" Target ----> Build Settings;
Search "name" or "Product Name",
Setting the "Product Name" (of "Extension" Target) to "app".

Target Properties changes by xcodebuild command

How can i manipulate my iOS Target Properties by xcodebuild command tool ?
In example, i have one project with one target and with Facebook SDK Key in Target Properties in Info tab
FacebookAppID: 01234567891234
And with console command xcodebuild i'm compiling two Apps with Developer and Production provisions with two console commands:
For Developer:
xcodebuild -project Projectname.xcodeproj clean install OBJROOT=ObjRoot ... CODE_SIGN_IDENTITY={iPhoneDeveloper} PROVISIONING_PROFILE="Dev.mobileprovision"
For Distribution:
xcodebuild -project Projectname.xcodeproj clean install OBJROOT=ObjRoot ... CODE_SIGN_IDENTITY={iPhoneProduction} PROVISIONING_PROFILE="Prod.mobileprovision"
And i need use in Developer one FacebookAppID, and in Production a other FacebookAppID, and how i can change my command lines for realize this?
Thanks
Arguments to xcodebuild are best used for values that change every time they're invoked, like a destination directory that includes a build number.
For data as foundational as a Facebook app ID, I'd recommend using your build configurations, e.g. "Debug" and "Release". Create a user-defined build setting (in Xcode 5.0.2, Editor -> Add Build Setting -> Add User-Defined Setting) named something like "FACEBOOK_ID", and in your Info.plist, set your desired key's value to ${FACEBOOK_ID}. In your target's build settings, define FACEBOOK_ID differently for your Debug and Release configurations. Your code then now has to pull the current value out of Info.plist at runtime.
If you really want to override build settings as arguments to xcodebuild, you can do so, just by adding "FACEBOOK_ID=12341234" to the end of the command, but this only works if you've done the work I just described to make FACEBOOK_ID into a configuration-specific build setting. I can't think of any sound reasons to keep this kind of app data outside of a build configuration.
If build configurations are new to you, I'd suggest starting with WWDC 2012 session 408, "Working with Schemes and Projects in Xcode".

Unable to build iOS project using command line but fine via Xcode interface

I have an Xcode project. When in Xcode interactively, I am able to run/build/archive using the Ad_Hoc_Distribution configuration but when I run:
/usr/bin/xcodebuild -configuration Ad_Hoc_Distribution clean build
inside my project, I get an error:
/Users/esg/Documents/app-ios/testapp/testapp/AppDelegate.h:14:9: fatal error: 'RestKit/RestKit.h' file not found
#import <RestKit/RestKit.h>
^
1 error generated.
What would cause this to fail from the command line when it works via the interface?
My team has encountered this same issue. After upgrading from Xcode 4.3.2 to 4.4.1, files that used to be found correctly no longer do.
By comparing the output of xcodebuild vs. Xcode's own build logs, and then comparing vs. our Xcode 4.3.2 build logs, we discovered that xcodebuild and Xcode IDE do not build with the same header dependencies anymore. When xcodebuild runs a 4.4.1 build, it uses an incorrect base directory for include files, which does not include the entire current path leading to the .xcodeproj directory. The last two directory nodes in the folder path appear to be truncated.
But building from Xcode IDE worked fine.
We worked around this problem by adding the correct header paths, as Xcode reports it, as an additional header dependency:
$(SRCROOT) is what seems to be interpreted incorrectly when xcodebuild is employed. It should contain the two subdirectories I inserted in the second line.
I can only conclude that there is a ripe and spicy new bug in the xcode/xcodebuild interaction, but you can fix your header dependencies to at least get things compiling.
See my own issue regarding this.
xcodebuild header files not found in ReskIt
I resolved it by changing nothing, but by adding a workspace and a scheme and used it to build. All the header settings were the same as it is being set for Xcode GUI to build.

Resources