How to link custom framework within UITest target in Xcode - another "Library not loaded - @rpath"-issue
Asked Answered
I

1

7

My project uses Xcode 11.3.1 and is structured as followed:

MyProject
 - MyProject.xcworkscapce
 - MyFramework 
 - MyApp
   -MyApp (main-target)
   -MyAppUITests (uiTest-target)

MyApp imports MyFramework and can be built und run just fine. For this to work I added MyFramework to main-target into main-targets General/Frameworks and Libraries.

In my UITest target I need to access some classes (Accessibility-Identifier-Definitions) from MyFramework, so I need to import these somehow.

Both targets are building and the main-target works without any issues. I am also able to run ui-tests on a simulator. Unfortunately I am forced to run my tests on real devices, and here I get this runtime error:

The bundle “MyAppUITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.

(dlopen_preflight(/var/containers/Bundle/Application/E581B3BA-A9A2-4AA3-A1BA-91C57DCD3846/MyAppUITests-Runner.app/PlugIns/MyAppUITests.xctest/FHCommunityUITests): Library not loaded: @rpath/MyFramework.framework/MyFramework

  Referenced from: /var/containers/Bundle/Application/E581B3BA-A9A2-4AA3-A1BA-91C57DCD3846/MyAppUITests-Runner.app/PlugIns/MyAppUITests.xctest/MyAppUITests
  Reason: image not found)

I am fairly new to this framework-thing (and also to ui-tests) and it's been two days I am dealing with this issue now. Most posts about similar issues are related to misspecified Podfiles, but in my barebone sample project which I setup to not destroy my real project I am not using any Pods. I tried probably all of the suggested solutions (and almost all combinations :() and none of them seem to work.

It took me a while to figure out that in my uiTest-target build phases I can actually add a New Run Script Phase and I assume I need to somehow link MyFramework here. Is this correct? Can someone help me defining the run script?

And yes, I tried to clean my app (and I also deleted derived data).

Help is highly appreciated. Thank you!

Illyes answered 5/2, 2020 at 15:35 Comment(0)
I
12

Ok, finally I figured it out. The solution is fairly simple and I haven't seen anyone suggesting this. Here we go:

To use your custom framework in your app target simply add it under Frameworks, Libraries, and Embedded Content:

enter image description here

Now you can access MyFramework from the main target. I could also run my ui-tests from the simulator, but still got the error described above when executing my ui-tests from my real devices.

To get rid of the The bundle “xxxUITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.-Error I had to go to my uiTest-target and link the framework in my build phases.

enter image description here

enter image description here

enter image description here

As Destination choose Frameworks and select the Framework you want to use in your uiTest-target.

Now you should be able to run your ui-Test from your device.

Illyes answered 6/2, 2020 at 21:6 Comment(2)
This answer is a buried gem! Thank you!Patois
Yea, for me also this answer save my day. Thank you stranger!!!Bcd

© 2022 - 2024 — McMap. All rights reserved.