dyld: could not load inserted library libXCTestBundleInject.dylib

Hi,

I'm running into weird issues on my CI machine. Building the app works fine, but trying to run the tests fails. This is using Xcode 12.4 on Catalina.

The command my CI server runs:
Code Block
Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk iphonesimulator -configuration Debug -workspace /users/ciuser/TFSBuilds/01/63/s/myapp.xcworkspace -scheme MyApp -destination "platform=iOS Simulator,name=iPhone 11" clean test DSTROOT=/users/ciuser/TFSBuilds/01/63/output/iphonesimulator/Debug/build.dst OBJROOT=/users/ciuser/TFSBuilds/01/63/output/iphonesimulator/Debug/build.obj SYMROOT=/users/ciuser/TFSBuilds/01/63/output/iphonesimulator/Debug/build.sym SHARED_PRECOMPS_DIR=/users/ciuser/TFSBuilds/01/63/output/iphonesimulator/Debug/build.pch CODE_SIGNING_ALLOWED=NO
Build settings from command line:
CODE_SIGNING_ALLOWED = NO
DSTROOT = /users/ciuser/TFSBuilds/01/63/output/iphonesimulator/Debug/build.dst
OBJROOT = /users/ciuser/TFSBuilds/01/63/output/iphonesimulator/Debug/build.obj
SDKROOT = iphonesimulator14.4
SHARED_PRECOMPS_DIR = /users/ciuser/TFSBuilds/01/63/output/iphonesimulator/Debug/build.pch
SYMROOT = /users/ciuser/TFSBuilds/01/63/output/iphonesimulator/Debug/build.sym
note: Using new build system
note: Building targets in parallel


It then takes several minutes to build everything. The failure occurs when it's trying to actually run the tests:

Code Block
2021-04-06 17:54:45.540 xcodebuild[20931:159027] [MT] IDETestOperationsObserverDebug: (A0071141-E59A-4B13-9576-04CA8A85FFAF) Beginning test session MyAppTests-A0071141-E59A-4B13-9576-04CA8A85FFAF at 2021-04-06 17:54:45.540 with Xcode 12D4e on target <DVTiPhoneSimulator: 0x7faf38a29a60> {
SimDevice: iPhone 11 (4923F5ED-5BA0-4054-B13B-0EBD8E6F617E, iOS 14.4, Shutdown)
} (14.4 (18D46))
2021-04-06 17:54:53.358 xcodebuild[20931:159027] [MT] IDETestOperationsObserverDebug: (A0071141-E59A-4B13-9576-04CA8A85FFAF) Finished requesting crash reports. Continuing with testing.
dyld: could not load inserted library '/users/ciuser/TFSBuilds/01/63/output/iphonesimulator/Debug/build.sym/Debug-iphonesimulator/MyApp.app/Frameworks/libXCTestBundleInject.dylib' because image not found
2021-04-06 17:55:13.156 xcodebuild[20931:159027] [MT] IDETestOperationsObserverDebug: 27.628 elapsed -- Testing started completed.
2021-04-06 17:55:13.156 xcodebuild[20931:159027] [MT] IDETestOperationsObserverDebug: 0.000 sec, +0.000 sec -- start
2021-04-06 17:55:13.156 xcodebuild[20931:159027] [MT] IDETestOperationsObserverDebug: 27.628 sec, +27.628 sec -- end
2021-04-06 17:55:16.737 xcodebuild[20931:159027] [MT] IDEResultKit: Warning: While writing a result bundle to /Users/ciuser/Library/Developer/Xcode/DerivedData/myapp-hkjgbcnyzsithfasuwjiardsqydl/Logs/Test/Run-MyApp-2021.04.06_17-50-57--0400.xcresult, not all contents have been imported, as the Staging directory still contains the following files/directories: ["2_Test"]
Test session results, code coverage, and logs:
/Users/ciuser/Library/Developer/Xcode/DerivedData/myapp-hkjgbcnyzsithfasuwjiardsqydl/Logs/Test/Run-MyApp-2021.04.06_17-50-57--0400.xcresult
Testing failed:
MyAppTests:
MyApp.app (26110) encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted. (Underlying Error: Crash: MyApp (26110): could not load inserted library '/users/ciuser/TFSBuilds/01/63/output/iphonesimulator/Debug/build.sym/Debug-iphonesimulator/MyApp.app/Frameworks/libXCTestBundleInject.dylib' because image not found. If you believe this error represents a bug, please attach the result bundle at /Users/ciuser/Library/Developer/Xcode/DerivedData/myapp-hkjgbcnyzsithfasuwjiardsqydl/Logs/Test/Run-MyApp-2021.04.06_17-50-57--0400.xcresult))
TEST FAILED


Running the same command locally on my machine works fine. Even when I log in to my CI machine and run this command directly in Terminal.app, I get the same failure. We delete both ~/Library/Developer/Xcode/DerivedData and /users/ciuser/TFSBuilds/01/63/output before each run.

Also, when I open Xcode on the CI machine and run the tests from the IDE, everything works fine as well. Just not when running it from the command line.

Any ideas?

Thank you!

Johannes

Replies

Has anyone found any solution to this? I'm running into the same issue. using Azure Devops for CI and the unit tests fail to run

Code Block
<REDACTED>.app (1699) encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted. (Underlying Error: Crash: <REDACTED> (1699): could not load inserted library '/Users/runner/Library/Developer/Xcode/DerivedData/<REDACTED>-gmtpdomxgkzvcoexdeckeovtovic/Build/Products/QA-Debug-iphonesimulator/<REDACTED>.app/Frameworks/libXCTestBundleInject.dylib' because image not found.

The tests work fine locally in Xcode but only fail when run on the DevOps agent.

I just hit this same situation.

XCode 12.1 iPhoneOS 11 Pro Simulator iOS 14.1

I don't know which step fixed it but I...

  1. Deleted the app from the iPhone simulator
  2. Restarted the simulator with Device-> Restart from the menu
  3. Restarted tests

I hit this same situation. (Xcode iPhone SE2 iOS 13.5) I just do: remove signing account and run the tests, let it show the ' signing for ...' error, and re-choose the account to sign. And fix it