Trying to run fastlane for a watchOS target, I found myself stuck at this error:
[...]
[18:18:04]: ▸ Processing Info.plist
[18:18:08]: ▸ Linking moria.debug.dylib
[18:18:09]: ▸ Linking moria
[18:18:09]: Running Tests: ▸ Touching moria.app (in target 'moria-watchOS' from project 'moria')
[18:18:09]: ▸ Build Succeeded
[18:18:09]: ▸ --- xcodebuild: WARNING: Using the first of multiple matching destinations:
[18:18:09]: ▸ { platform:watchOS Simulator, id:2F3EFDE2-C515-4C2D-8231-20F4250D2B66, OS:11.1, name:Apple Watch Ultra (49mm) }
[18:18:09]: ▸ { platform:watchOS Simulator, id:2F3EFDE2-C515-4C2D-8231-20F4250D2B66, OS:11.1, name:Apple Watch Ultra (49mm) }
[18:18:09]: ▸ 2024-12-05 18:18:09.209 xcodebuild[68726:4065663] Writing error result bundle to /var/folders/p2/km38m51j3mndjw93wypkd3_80000gp/T/ResultBundle_2024-05-12_18-18-0009.xcresult
[18:18:10]: ▸ xcodebuild: error: Failed to build project moria with scheme moria-watchOS.: Could not find test host for Tests-watchOS: TEST_HOST evaluates to "/var/folders/p2/km38m51j3mndjw93wypkd3_80000gp/T/snapshot_derived20241205-68477-ve5y3u/Build/Products/Debug-watchsimulator/moria Watch App.app/moria Watch App"
It could not find the test host?
Searching for the TEST_HOST setting, I can see in the log files, during the execution of one of my pre-build scripts, that there is:
[18:43:45]: ▸ export TEST_FRAMEWORK_SEARCH_PATHS=" /Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/Library/Frameworks watchsimulator11.1/Developer/Library/Frameworks"
[18:43:45]: ▸ export TEST_HOST=
[18:43:45]: ▸ export TEST_LIBRARY_SEARCH_PATHS=" /Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/usr/lib"
So TEST_HOST is "" ??
Well, searching for "TEST_HOST" in Xcode gave no results.
Neither did searching the Internet.
(ONE WEEK LATER)
But my egg search alias found something else. This is a deep directory search in the UNIX shell, opening the matches in an editor. My zsh aliases are:
gf - Grep Files
gf () { find -L . \( -name "*~" -o -name "*.bak" -o -name ".git" \
-o -name "*.png" \) -prune -o -type f \
-exec grep -l $* {} ; | sed "s/\\ / /g" }
egg - Edit Grep files in GUI
egg () { gf $* | eval xargs $VISUAL +/$* }
where $VISUAL is the name of your preferred GUI-based text editor; for me that is set to "mvim -f".
Where is the TEST_HOST?
Searching from within the Xcode $PROJECT_DIR:
egg TEST_HOST
Opens the text editor for these files:
./moria.xcodeproj/project.pbxproj
./moria.xcodeproj/project.xcworkspace/xcuserdata/gimli.xcuserdatad/UserInterfaceState.xcuserstate
The second one is binary property list which probably has cached my search string. The first, however, reveals settings like these for the test targets:
TEST_TARGET_NAME = "moria Watch App";
and:
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/moria Watch App.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/moria Watch App";
...which were incorrect after I had previously changed the $PRODUCT_NAME for the watchOS target. Sigh. Let's fix this.
- First of all, don't edit any xcodeproj files while the project is open in Xcode, so cllose the project in Xcode.
- Correct the names in your text editor such that the settings for the test targets match the
$PRODUCT_NAMEof the watchOS target. - Then open the project again in Xcode.
Example updates:
TEST_TARGET_NAME = "moria";
and:
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/moria.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/moria";
Now fastlane works.
