Reputation: 2168
I'm trying to setup some UI tests but can't get them to run on devices running pre iOS 12.3.
Even if I start a fresh swift project with 'include UI tests' ticked and try to run the UI tests straight away on a pre iOS 12.3 device I get the following:
2019-05-22 15:42:41.543630+0100 testUITests-Runner[461:45630] Running tests... 2019-05-22 15:42:41.601954+0100 testUITests-Runner[461:45630] The bundle “testUITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle. 2019-05-22 15:42:41.602043+0100 testUITests-Runner[461:45630] (dlopen_preflight(/var/containers/Bundle/Application/50D1F2AB-69B9-4C3D-B36B-F84F838E3301/testUITests-Runner.app/PlugIns/testUITests.xctest/testUITests): Library not loaded: @rpath/libswiftCore.dylib Referenced from: /var/containers/Bundle/Application/50D1F2AB-69B9-4C3D-B36B-F84F838E3301/testUITests-Runner.app/PlugIns/testUITests.xctest/testUITests Reason: image not found)
I've seen various questions and answers for the same errors going back to betas of Xcode 6 but none of the suggestions there have helped, including:
I started on Xcode 10.2 and found the issue, upgrading to Xcode 10.3 hasn't helped.
It was working fine on the 12.2 simulator but fails on a device.
Upvotes: 1
Views: 668
Reputation: 2168
The answer to this is infuriatingly simple. Just make sure, in your build settings, that the UI tests target has the same deployment target as the app.
I'd changed the app to target down to iOS 10 but hadn't thought I'd need to make the same change for the UI tests target.
I'd imagine this is something that should be auto-synced for us, presumably no reason to have them targeting different versions really
Upvotes: 1
Reputation: 2168
I've found a workaround for this issue, though it's not necessarily reliable for future versions of Xcode so be wary if you decide to try this out (maybe you'd need to repeat the process after an Xcode upgrade).
If you go to the following directory you'll find all the swift libraries for iPhone devices:
Applications ▸ Xcode ▸ Contents ▸ Developer ▸ Toolchains ▸ XcodeDefault.xctoolchain ▸ usr ▸ lib ▸ swift ▸ iphoneos
You can copy those into your UI tests target (not the app being tested) and then add a copy files build phase to bundle the libraries into the test runner, such that they can be found at runtime. You don't need all the swift libraries, the following image shows which ones I found to be required:
It's also worth noting that this messes up running the tests on simulator (no doubt in part because these swift libraries that have been copied are the versions for a device), though there may be a way to get around that or maybe that's fine if you don't intend to run them on the simulator
Upvotes: 0
Reputation: 69
I have 2 guesses,
Did you download the the components for the ios versions in components?
Turn your computer on and off & worse case uninstall and reinstall xcode.
Upvotes: 0