Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with test spec / static linkage / XCFramework - Failed to load the test bundle. The bundle is damaged or missing necessary resources. Library not loaded. Reason: image not found. #10652

Closed
1 task done
OliverPearmain-Triller opened this issue May 13, 2021 · 16 comments · Fixed by #10830
Labels
d2:moderate A moderately-difficult ticket that may require a bit of knowledge about the codebase s2:confirmed Issues that have been confirmed by a CocoaPods contributor t2:defect These are known bugs. The issue should also contain steps to reproduce. PRs welcome!
Milestone

Comments

@OliverPearmain-Triller
Copy link

Report

The unit tests (test spec) of a certain local/development pod fail at run time with the following error:

Screenshot 2021-05-13 at 11 12 52

Assertions: System: Failed to load the test bundle. If you believe this error represents a bug, please attach the result bundle at /Users/okp/Library/Developer/Xcode/DerivedData/DemoApp-bmsiniphoqhqciawekumfhsuqwjj/Logs/Test/Test-DemoApp-2021.05.13_11-11-46-+0100.xcresult. (Underlying Error: The bundle “SomeModule-Unit-Tests” couldn’t be loaded because it is damaged or missing necessary resources. The bundle is damaged or missing necessary resources. Try reinstalling the bundle. dlopen_preflight(/Users/okp/Library/Developer/Xcode/DerivedData/DemoApp-bmsiniphoqhqciawekumfhsuqwjj/Build/Products/Debug-iphonesimulator/SomeModule-Unit-Tests.xctest/SomeModule-Unit-Tests): Library not loaded: @rpath/MUXSDKStats.framework/MUXSDKStats
  Referenced from: /Users/okp/Library/Developer/Xcode/DerivedData/DemoApp-bmsiniphoqhqciawekumfhsuqwjj/Build/Products/Debug-iphonesimulator/SomeModule-Unit-Tests.xctest/SomeModule-Unit-Tests
  Reason: image not found)

The error seems to manifest because:

  • The Podfile specifies use_frameworks! :linkage => :static
    (if you change to use_frameworks! only, things work fine)

  • The development pod/module has an XCFramework dependency (Mux-Stats-AVPlayer)
    (if you change SomeModules dependency from Mux-Stats-AVPlayer to RxSwift, things work fine)

Unfortunately I am not able to change either of these things in my reall-world project.

Workarounds tried and failed:

I have tried the following, as suggested in other threads, but the outcome is exactly the same...

  • test_spec.requires_app_host = true
  • "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES" => "YES"

What did you do?

What did you expect to happen?

SomeModule-Unit-Tests run and pass
DemoAppTests run and pass

What happened instead?

SomeModule-Unit-Tests do not run. They encounter the run time error mentioned above.
DemoAppTests run and pass

CocoaPods Environment

Stack

   CocoaPods : 1.10.1
        Ruby : ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
    RubyGems : 3.1.2
        Host : macOS 11.2.1 (20D75)
       Xcode : 12.4 (12D4e)
         Git : git version 2.28.0
Ruby lib dir : /Users/okp/.rbenv/versions/2.7.1/lib
Repositories : cocoapods - git - https://github.com/CocoaPods/Specs.git @ 2d42b44d22a8a238f6f0ff8b271e5c18678de571

               gitlab-mxx-podspecs - git - https://triller-iosdevs:d_5uy-uuZNrGeXbvuuT6@gitlab.com/mxx-ios-kits/mxx-podspecs.git @ ef7590b0aab9f97b2f2acca93bf465637e5a00ef

               trillerco - git - https://github.com/TrillerCo/private-pod-trunk.git @ caad05a7e0f23452a61e767f0eae58a89e4ee9e0

               trunk - CDN - https://cdn.cocoapods.org/

Installation Source

Executable Path: /Users/okp/.rbenv/versions/2.7.1/bin/pod

Plugins

cocoapods-binary       : 0.4.4
cocoapods-deintegrate  : 1.0.4
cocoapods-dependencies : 1.3.0
cocoapods-plugins      : 1.0.0
cocoapods-search       : 1.0.0
cocoapods-stats        : 1.1.0
cocoapods-trunk        : 1.5.0
cocoapods-try          : 1.2.0

Podfile

platform :ios, '12.0'

use_frameworks! :linkage => :static

target 'DemoApp' do

  pod 'SomeModule', :path => 'Modules/SomeModule', :testspecs => ['Tests']

  target 'DemoAppTests' do
  end

end

Project that demonstrates the issue

https://github.com/OliverPearmain/CocoapodsTestBundleIssueExample

@Mainstayz
Copy link

Is there a solution?

@OliverPearmain-Triller
Copy link
Author

Is there a solution?

I haven't found one yet I'm afraid. I am hoping someone much wiser than me might be able to help 🤞

@acecilia
Copy link

acecilia commented Jul 1, 2021

I could also reproduce this issue when having a static local development pod depending on a prebuilt dynamic xcframework. Changing the prebuilt dynamic xcframework to prebuilt dynamic framework makes the issue go away

@OliverPearmain-Triller
Copy link
Author

@acecilia thanks, this is useful for others to know but I am unforrtunately not able to change the framework type output from a third party dependency. So I am still in need of help please 🙏 .

@OliverPearmain-Triller
Copy link
Author

Someone on my team discovered something that might be relevant to fixing this issue, so I thought I'd share.

If you compile the example project (for testing) then the Products/Debug-iphonesimulator directory (in DerivedData) looks like this...
Screenshot 2021-07-05 at 16 19 26

Running the unit tests at this stage, will result in the runtime error described in the OP.

HOWEVER if you manually copy and paste the MuxCore.framework and MUXSDKStats.framework directly into the root of Products/Debug-iphonesimulator like so...
Screenshot 2021-07-05 at 16 19 39

when you re-run the tests, they will SUCCEED.

So there is possibly an issue with search paths? I've tried manually modifying FRAMEWORK_SEARCH_PATHS adding hardcoded paths to both of the frameworks but I've been unable to get that working. 😡

@dnkoutso
Copy link
Contributor

dnkoutso commented Jul 5, 2021

this seems like a bug that the xcframeworks are not embedded to unit test targets or even in the app hosts if they specify one.

The reason the screenshot you pasted above works is because that is a default search path that is being searched and so that works.

@dnkoutso dnkoutso added this to the 1.11.0 milestone Jul 5, 2021
@dnkoutso dnkoutso added t2:defect These are known bugs. The issue should also contain steps to reproduce. PRs welcome! d2:moderate A moderately-difficult ticket that may require a bit of knowledge about the codebase labels Jul 5, 2021
@OliverPearmain-Triller
Copy link
Author

Thanks for your input @dnkoutso

In case its useful, the FRAMEWORK_SEARCH_PATHS of the SomeModule target are...

Screenshot 2021-07-06 at 08 29 03

and the SomeModule-Unit-Tests target...

Screenshot 2021-07-06 at 08 33 08

So I guess its the last two entries that are of interest.

@dnkoutso
Copy link
Contributor

yeah I think I was a bit off in my initial statement, this is a runtime issue, basically the frameworks are not copied inside the test bundle as they should.

@dnkoutso
Copy link
Contributor

I read the issue above a bit more, things can be a bit interesting because those are statically linked...I need to dig further.

@dnkoutso
Copy link
Contributor

I took another look, yes it seems we are not embedding the frameworks that were produced by the xcframework into test bundles or their app hosts (if they have any).

I continue to believe it works if you copy over the framework to the top level folder because its probably searched as a runpath to load frameworks from by default.

It does not appear to be a header search paths issue per se, otherwise we would see compilation failures vs runtime dyld errors.

@dnkoutso dnkoutso added the s2:confirmed Issues that have been confirmed by a CocoaPods contributor label Aug 2, 2021
@dnkoutso
Copy link
Contributor

dnkoutso commented Aug 2, 2021

More inspection this appears to be a bug actually. The embed frameworks script is being written but the unit test target does not get the phase added to it.

@OliverPearmain-Triller
Copy link
Author

Thanks for the updates @dnkoutso. Really appreciate your efforts looking into this 🙏

@dnkoutso
Copy link
Contributor

dnkoutso commented Aug 3, 2021

PR! #10830

@OliverPearmain-Triller thank you a lot for the great report and sample app, helped a lot! I verified it builds successfully with my change.

@dnkoutso
Copy link
Contributor

dnkoutso commented Aug 3, 2021

here are the tests running correctly.

Screen Shot 2021-08-03 at 12 14 35 PM

@falcon283
Copy link

Hello there.
I have exactly the same issue on my project, I still need to exclude arm64 due to some 3rd party dependencies does not support it yet.
I updated to cocoapods 1.11.0 first and then to 1.11.2 but none of them seems to fix the issue.
When the test spec is kicked in it try to spin the arm64 version, not available in my case, and it crash at runtime due to missing library.

Assertions: System: Failed to load the test bundle. If you believe this error represents a bug, please attach the result bundle at /Users/homefolder/Library/Developer/Xcode/DerivedData/MyApp-adaodxmfodqrmeenzupvfhikvhij/Logs/Test/Test-Debug-2021.11.13_12-23-50-+0100.xcresult. (Underlying Error: The bundle “MyApp-Kit-Unit-Tests” couldn’t be loaded because it doesn’t contain a version for the current architecture. The bundle doesn’t contain a version for the current architecture. Try installing a universal version of the bundle. dlopen_preflight(/Users/homefolder/Library/Developer/Xcode/DerivedData/MyApp-adaodxmfodqrmeenzupvfhikvhij/Build/Products/DebugStaging-iphonesimulator/MyApp-Kit-Unit-Tests.xctest/MyApp-Kit-Unit-Tests): no suitable image found.  Did find:
	/Users/homefolder/Library/Developer/Xcode/DerivedData/MyApp-adaodxmfodqrmeenzupvfhikvhij/Build/Products/DebugStaging-iphonesimulator/MyApp-Kit-Unit-Tests.xctest/MyApp-Kit-Unit-Tests: mach-o, but wrong architecture)

I will try to reopen another issue as soon as I have a test project to attach

@falcon283
Copy link

Actually this is still open that describe the same issue
#10733

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
d2:moderate A moderately-difficult ticket that may require a bit of knowledge about the codebase s2:confirmed Issues that have been confirmed by a CocoaPods contributor t2:defect These are known bugs. The issue should also contain steps to reproduce. PRs welcome!
Projects
None yet
5 participants