hmlongco / Resolver

Swift Ultralight Dependency Injection / Service Locator framework
MIT License
2.15k stars 190 forks source link

Could not find module 'Resolver' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios-simulator #136

Closed brentjensen closed 2 years ago

brentjensen commented 3 years ago

When you try to build for x86_64 simulator, Resolver can't be found, because it does not appear to be built for this architecture. Is there a way to add this to the supported architectures?

To reproduce:

  1. Add Resolver swift package to your project and import it into a file.
  2. Add "arm64" in the "Excluded Architectures" build setting for your project. (this is needed when 3rd party libraries have not yet been built for Apple Silicon)
  3. Attempt to build your application.
brentjensen commented 3 years ago

Forgot to mention. I'm configured to use Resolver 1.4.1 in Swift Package Manager.

hmlongco commented 3 years ago

Looking into this as just got an M1 machine.

eungkyu commented 2 years ago

I also experienced this issue on M1 mac, it turned out that Resolver is not the cause of the problem after all. I had one binary-only pod which is not compatible with arm64 simulator, and it was the problem. Excluding this pod solved the problem. In the end, I added build configuration only for simulator without that binary-only pod.

horovodovodo4ka commented 2 years ago

same here but via cocoapods

brentjensen commented 2 years ago

I managed to create a universal xcframework to fix this. The steps will hopefully help you resolve it in a way that doesn't force so many compromises, or others having this issue can follow these steps for a temporary workaround. Most of these steps were required because of the restrictions of XCFramework, so if you can, it would be much better to figure out how to get lipo to combine two arm64 frameworks (Apple Silicon Simulator and iOS builds will both contain this architecture).

There are a lot of steps here, but they should take only about 10 mins or less to complete.

  1. Download the code base on master branch (commit bd565aae33a08dd4e10747bfb98e2bf8a63bfa28)
  2. On the "Resolver" target, update the build setting BUILD_LIBRARY_FOR_DISTRIBUTION = YES (this generates to swift interface files required for xcframework)
  3. Update the Target name, and the build setting TARGET_NAME to Resolve (instead of "Resolver"). The definition of an xcframework confuses the compiler when a class is named the same thing as its module. The product module name is configured to rely on this user defined build setting TARGET_NAME.
  4. I updated the Product Bundle Identifier to "Resolve" as well, just for parity (probably no real reason to do this).
  5. In Resolver.swift, import Combine right above the definition for the struct InjectedObject, but inside the #if directive. (Otherwise, the xcframework swift definition file gets really confused about using Combine.ObservableObject because it chooses to fully qualify this symbol, instead of using the alias found in Foundation)
  6. Switch the "Run" "Build Configuration" to "Release" in the scheme editor (cmd-shift-comma).
  7. Build the product for both a simulator and for "Any iOS Device".
  8. In the Project Navigator, open the Products folder, right-click on the Resolve framework, and select Show in Finder. This will allow you to copy the two Resolve.framework folder paths for the next step.
  9. Run this command in the Terminal (after you replace the 3 locations with your own applicable values): xcodebuild -create-xcframework \ -framework "<YOUR_BUILD_PATH>/Release-iphonesimulator/Resolve.framework" \ -framework "<YOUR_BUILD_PATH>/Release-iphoneos/Resolve.framework" \ -output "<YOUR_BUILD_PATH>/Universal/Resolve.xcframework"
  10. Copy this Resolve.xcframework to the location where you'll want it for your project, remove your existing Resolver, and then drag this xcframework into your Project Navigator (you don't need Copy items, but make sure each target you want to use Resolver in is checked in the modal dialog that appears).
  11. FINALLY, in each Target you added Resolver to, go to the "General" tab, scroll down to "Frameworks, Libraries, and Embedded Content" and choose "Embed & Sign" for the "Resolve.xcframework".
brentjensen commented 2 years ago

Oh, and of course this module name change means you'll need to import Resolve everywhere you had import Resolver

hugovanderlei commented 2 years ago

Any news about this issue?