2

If I run my app from Xcode 12.3, I can launch it on my Iphone 11. But running the app on the phone fails. The device log gives the following error in a package (Mocker) that I am using:

Termination Description: DYLD, dyld: Using shared cache: 
EEFDD874-2301-31BF-B255-11CE61E827BD | dependent dylib 
'@rpath/XCTAutomationSupport.framework/XCTAutomationSupport'
 not found for 
'/private/var/containers/Bundle/Application/
E5F4D064-2097-4978-AFB5-954DC355F686/Things.app/Frameworks/
Mocker.framework/Frameworks/XCTest.framework/XCTest', tried but didn't find: 
'/usr/lib/swift/XCTAutomationSupport.framework/XCTAutomationSupport' 
'/private/var/containers/Bundle/Application/
E5F4D064-2097-4978-AFB5-954DC355F686/Things.app/Frameworks/
XCTAutomationSupport.framework/
XCTAutomationSupport' 
'/private/var/containers/Bundle/Application/E5F4D064-2097-4978-AFB5-
954DC355F686/Things.app/Frameworks/Mocker.framework/Frameworks/
XCTAutomationSupport.
framework/XCTAutomationSupport' '@rpath/XCTAutomationSupport.framework/
XCTAutomationSupport' 
'/System/Library/Frameworks/XCTAutomationSupport.framework/
XCTAutomationSupport'

Clearly, this is a problem where some package can be found or not found depending on specification. How would I move forward? If possible, I'd appreciate an understanding of how this can even happen - what makes it possible that libraries become unavailable when running from the phone instead of being launched from Xcode (on the same phone)?

cgold
  • 4,075
  • 1
  • 12
  • 13
  • you shouldn't be running unit tests on the device - are you sure you're not importing mocker in the application target (not testing targets)? remove these imports from the main app – Pranav Kasetti Jan 01 '21 at 02:55
  • also you can confirm that it's an Xcode runtime bug if you disable some scheme settings as described in my answer [here](https://stackoverflow.com/questions/63342162/cannot-build-project-with-xcode-12-0-beta-5/63822837#63822837), and it works. – Pranav Kasetti Jan 01 '21 at 02:58
  • @PranavKasetti thanks, Will check into your other SO answer. On the first comment, I think there are good use cases for using Mocker on my phone. For instance, I might have a setting where I mock up the api on my device to run the app more quickly. Nothing about Mocker I've seen rules out this case (https://github.com/WeTransfer/Mocker). Obviously you know this much better, so please correct if I misunderstand the package. – cgold Jan 01 '21 at 02:59
  • Mocker depends on XCTest and to get XCTest to link in an application target requires more setup and configuration - the libraries won't be found it we don't modify the project linked frameworks. Have you followed the steps [here](https://stackoverflow.com/questions/43715195/is-it-possible-to-run-xctest-tests-in-an-ios-app)? – Pranav Kasetti Jan 01 '21 at 03:08
  • Usually you can use Mocker inside the test target, and run that on the device with no issues (although for automation/CI and faster results I use sims) - running tests on the app target is more work, given Apple sandboxes the filesystem on the iOS device. – Pranav Kasetti Jan 01 '21 at 03:10
  • Thanks, it does look like Mocker's dependency on XCTest is creating the problem. It's a bit mysterious to me still because Mocker does build (even though it imports XCTest). I've asked the Mocker team directly about this use case (as a Github issue) because to me its seems quite natural and useful to apply Mocker this way. Your comment is of course an answer I'm very happy to accept. Really appreciated. – cgold Jan 01 '21 at 18:42
  • You have to "embed" the lib. It's a dynamic lib. Without embedding it to the app bundle, it's not there on device at runtime. – shallowThought Jan 02 '21 at 16:43
  • Ok, I've added an answer @cgold. – Pranav Kasetti Jan 02 '21 at 17:35

1 Answers1

1

The reason this fails at runtime rather than compile-time is that Mocker is trying to find the XCTest dynamic library - these are only loaded at runtime.

The framework is missing in the Application Bundle - can be seen from the error log:

not found for 
'/private/var/containers/Bundle/Application/
E5F4D064-2097-4978-AFB5-954DC355F686/Things.app/Frameworks/
Mocker.framework/Frameworks/XCTest.framework/XCTest

Add the dylib to the Linked Frameworks and Libraries of the application target, follow the steps here and there are lots of other SO questions related to embedding XCTest.framework into an application target.

This isn't a problem for testing targets, since they have already been added on both the simulator and device runtimes.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Pranav Kasetti
  • 8,770
  • 2
  • 50
  • 71