SolvedCocoaPods XCFrameworks slice selection fails in multiple ways

Report

What did you do?

Integrating a pod distributed as a xcframework.

What did you expect to happen?

The xcframework pod to be handled properly by Cocoapods and for the target to compile without errors.

What happened instead?

The shell script generated by copy_xcframework_script.rb does not handle all xcframeworks correctly.

Example 1

Given the following xcframework:

SampleXCFramework.xcframework
├── Info.plist
├── ios-arm64
│   └── SampleXCFramework.framework
│       └── ...
└── ios-arm64_x86_64-simulator
    └── SampleXCFramework.framework
        └── ...

When compiling on a device or using the Any iOS Device destination. The pod's copy_xcframework_script.rb will select the simulator slice instead of the device slice.

Screen Shot 2020-09-02 at 2 13 57 PM

This leads to the following compilation error on the target:

Building for iOS, but linking in dylib file (.../SampleXCFramework.framework/SampleXCFramework) built for iOS Simulator, file '.../SampleXCFramework.framework/SampleXCFramework' for architecture arm64

Example 2

Given the following xcframework:

AppboyKit.xcframework
├── Info.plist
├── ios-arm64_armv7
│   ├── Headers
│   │   └── ...
│   └── libAppboyKitLibrary.a
└── ios-arm64_i386_x86_64-simulator
    ├── Headers
    │   └── ...
    └── libAppboyKitLibrary.a

When compiling on a device or using the Any iOS Device destination. The pod's copy_xcframework_script.rb will fail to select a slice in the xcframework:

[CP] Unable to find matching .xcframework slice in '.../AppboyKit.xcframework AppboyKit library ios-arm64_i386_x86_64-simulator ios-arm64_armv7' for the current build architectures (armv7 arm64).

As you can see, the slice ios-arm64_armv7 contains all the architectures needed (armv7 arm64). The script fails to select this slice due to the following regex:

# This regex matches all possible variants of the arch in the folder name:
# Let's say the folder name is: ios-armv7_armv7s_arm64_arm64e/CoconutLib.framework
# We match the following: -armv7_, _armv7s_, _arm64_ and _arm64e/.
# If we have a specific variant: ios-i386_x86_64-simulator/CoconutLib.framework
# We match the following: -i386_ and _x86_64-
local target_arch_regex="[_\-]${target_arch}[\/_\-]"

That regex fails to match the target architecture in the string ios-arm64_armv7. A possible fix for that regex is:

"[_\-]${target_arch}([\/_\-]|$)"

Notes

In both examples, the xcframeworks were:

  • generated using Xcode 12 beta 6
  • tested and work correctly when integrated manually into an Xcode project

CocoaPods Environment

Stack

   CocoaPods : 1.10.0.beta.2
        Ruby : ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin19]
    RubyGems : 3.0.1
        Host : Mac OS X 10.15.6 (19G2021)
       Xcode : 12.0 (12A8189n)
         Git : git version 2.28.0
Ruby lib dir : /Users/louis.bur/.rbenv/versions/2.6.1/lib
Repositories : cocoapods - git - https://github.com/CocoaPods/Specs.git @ a73178d31cff733dba361b7b9332648ff995121d

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

Installation Source

Executable Path: /Users/louis.bur/.rbenv/versions/2.6.1/bin/pod

Plugins

cocoapods-deintegrate : 1.0.4
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.0
cocoapods-stats       : 1.1.0
cocoapods-trunk       : 1.4.1
cocoapods-try         : 1.1.0

Podfile

platform :ios, '14.0'
project 'SampleApp.xcodeproj'

target :SampleApp do
  pod 'SampleXCFramework', :path => './'
end

Project that demonstrates the issue

Example 1 - SampleXCFramework.zip
Example 2 - AppboyKit.xcframework.zip

18 Answers

✔️Accepted Answer

@trevinwisaksana I had this same issue with the AppCenter Cocoapod today. I fixed it by removing an recursive path ($(SRCROOT)/**) from the Framework Search Path in the target (though it could also be in the project) Build Settings.

The recursive path was causing XCode to add every folder into the Link step including (incorrectly) the architecture folders inside of the xcframework, and using those paths it would find the wrong architecture framework. You can tell if this is the case by looking at the Link step log
image
for paths similar to this:

-FPods/AppCenter/AppCenter-SDK-Apple/AppCenter.xcframework/ios-arm64_arm64e_armv7_armv7s
-FPods/AppCenter/AppCenter-SDK-Apple/AppCenter.xcframework/ios-arm64_i386_x86_64-simulator
-FPods/AppCenter/AppCenter-SDK-Apple/AppCenter.xcframework/ios-arm64_x86_64-maccatalyst
-FPods/AppCenter/AppCenter-SDK-Apple/AppCenter.xcframework/macos-arm64_x86_64
-FPods/AppCenter/AppCenter-SDK-Apple/AppCenter.xcframework/tvos-arm64
-FPods/AppCenter/AppCenter-SDK-Apple/AppCenter.xcframework/tvos-arm64_x86_64-simulator

Other Answers:

I believe this bug or at least a variation of it might still be occurring. I'm getting a build issue only on my Development configuration because Cocoapods is selecting the wrong slice of the XCFramework. This prevents me from building for a simulator but it works normally when building for a device.

Screen Shot 2020-12-01 at 09 07 38

It correctly selected the correct slice at first as shown on the logs. But then notice that it's still looking for the x86_64 architecture in the ios-arm64_armv7 folder.
missing required architecture x86_64 in file Pods/Crisp/Crisp.xcframework/ios-arm64_armv7/Crisp.framework/Crisp (2 slices)

I'm using Xcode 12.2 and Cocoapods 1.10 to generate this.

Related Issues:

765
655
CocoaPods [error report] pod install /w m1 macbook
do you have a MacBook Pro with a M1 processor? this fixed my issue: Report What did you do? Run pod ...
392
CocoaPods NoMethodError - undefined method `size' for nil:NilClass
Also faced with this issue Fixed by updating flutter and cocoa pods to the latest version and then ...
247
CocoaPods pod install has bug
Did you try: sudo arch -x86_64 gem install ffi And run: arch -x86_64 pod install instead of pod inst...
186
CocoaPods CocoaPods was not able to update the master repo
Looks like your specs repo was edited at some point and now git can't update it ...
182
CocoaPods CocoaPods compatibility with Apple DTK (Apple Silicon)
For anyone else struggling with this issue I just found a way to solve it In addition to running ter...
175
CocoaPods Build issue with Xcode 12.3 - file not found #include "ruby/config.h"
I just updated to Xcode 12.3 and I am hitting this issue Seems like Xcode 12.3 broke the system ruby...
169
CocoaPods Unzip fail when zip contains chinese char on macOS 10.13
Maybe replace unzip with ditto: I have a SDK and there is a folder named FaceDistortion_20171205雪天的雪...
163
CocoaPods None of your spec sources contain a spec satisfying the dependencies
Did you note this part of the error message: Note: as of CocoaPods 1.0 pod repo update does not happ...
145
CocoaPods pod install fails with json error on Mac OS X 10.15
I did rm -rf ~/.cocoapods/repos/trunk/ After that it worked again. I've read and understood the CONT...
124
CocoaPods No such file or directory @ rb_sysopen -- AppCenter -- ReactNative
So I updated my appcenter dependencies from v2.4.0 to v2.5.0 and I'm having this issue again 🙄 Edit...
122
CocoaPods App Icons not included in build from Xcode 9
I have the same problem Report What did you do? Run project on device from Xcode 9 Beta 6 What did y...
113
CocoaPods Intermittent CDN issues
The workaround to get working locally during this outage or CDN issue - guessing a DNS change or som...
89
CocoaPods new Macbook M1 crash
As a temporary fix I've installed cocoapods using sudo arch -arch x86_64 gem install cocoapods then ...
83
CocoaPods Support multiple Swift versions on a per pod basis
this works: It's not pretty but will do until they update your pods to Swift 4. ...
80
CocoaPods pod update error with CDN
And? How to fix? gem install concurrent-ruby or gem update concurrent-ruby. I've read and understood...
71
CocoaPods Failed to build gem native extension. Header file missing,
I had the same problem on macOS Mojave 10.14.16 A few threads eventually lead me here which solved i...
54
CocoaPods I can not install pod files.
Nope Just do: Install ffi sudo arch -x86_64 gem install ffi Re-install dependencies arch -x86_64 pod...
52
CocoaPods CocoaPods1.9.0 cannot install on Mojave10.14.6
This should be re-opened I can repro on a clean Mojave The workaround is to run sudo gem install coc...
46
CocoaPods [Xcode 8 beta 2]: CopySwiftLibs for Pods framework fails with Mach-O header error
I've found a workaround Add the following lines to your Podfile: 🌈 I've read and understood the *CO...
45
CocoaPods FBSDKLoginKit can not find headers under 1.0.0
This appears to be some issue between CocoaPods and XCode I tried to reproduce the problem I was see...
40
CocoaPods Podfile without use_frameworks! triggers "deployment target" warnings in Xcode 10
For those wanting a quick fix: edit: updated snippet now supports the new generate_multiple_pod_proj...
37
CocoaPods Resources installed using cocoapods not loaded for xctest bundle
For me I fixed it by setting Host Application to main target (In Test Target -> `General) ...
36
CocoaPods CDN: trunk Repo update failed - 2 error(s):
pod repo list 查看源列表 pod repo remove trunk 移除trunk源 只有移除掉问题才解决!!! 2019.11.07更 怕有人不懂,特意写了一篇文章 具体操作看下这篇...
36
CocoaPods [1.9.2] Error during pod install JSON::ParserError - 767: unexpected token
Running only sudo rm -rf ~/.cocoapods/repos and then pod install was enough for my case. ...
35
CocoaPods pod lib create fails: uninitialized constant Nanaimo::Reader::StringScanner (NameError)
gem uninstall nanaimo It will prompt you for which version to uninstall 👍 Before you start ...
35
CocoaPods pod install triggers pods to use Swift 4.2 in XCode 10
I was also facing the same problem and able to fix by adding swift_version in pre_install block Is t...
32
CocoaPods pod spec lint fails (Xcode 8 GM & Cocoapods 1.1.0.rc.1)
Got it working using the .swift-version file mentioned in #5841 For those who need help make a .swif...
32
CocoaPods undefined method `map' for nil:NilClass (NoMethodError) Did you mean? tap
ah gem update xcodeproj fixes the problem for me I've read and understood the CONTRIBUTING guideline...
31
CocoaPods error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
This seems like an issue with cloning the master repo Could be an issue with your connection or the ...
31
CocoaPods Malformed version number string
if your rubyGems version is 2.7.7 or higher you just can do like this gem update --system 2.7.6 my p...
30
CocoaPods Pod with swift 4.2 fails at linting
The podspec contains s.source_files = Constrictor/Constrictor/**/* which includes all files includin...
25
CocoaPods LoadError - cannot load such file -- macho
TBH I'm not familiar with ruby so this may be a terrible solution I tried with versions 1.5.0 and 1....
24
CocoaPods Modules not found in test targets
Thanks for the great ticket! So pods would be passed to a target by inheritance here but you're not ...
24
CocoaPods Duplicate symbols when framework target has a static dependency
I have a new version of the workaround It works when some static libraries are only used in the Appl...
23
CocoaPods UITests missing 📦 Embed Pods Frameworks build phase in 1.0.0.rc.1
Moving the UITests target outside of the main target in the Podfile seems to have helped So now inst...
22
CocoaPods Fails to install cocoapods on Ruby 2.4
Luckily cocoapods v1.0.1 still works Reproduction Detail CocoaPods has dependency in activesupport g...
20
CocoaPods Unit tests do not run on iOS 11 devices on Xcode 11 when using dynamically linked libraries
@dvataksi16 I got a response from Apple with a non-hacky solution: After reviewing your feedback we ...
19
CocoaPods 🐛 : Unable to install pods using custom build configurations
Just to leave a clear solution here Thankfully the solution is already merged to RN 0.63.3 ...
19
CocoaPods pod install: [!] Oh no, an error occurred.
This was what worked for me - arch -x86_64 pod install Report [!] Oh no an error occurred ...
19
CocoaPods Raise default macOS/iOS deployment target
The same is happening with iOS btw I've read and understood the CONTRIBUTING guidelines and have don...
18
CocoaPods Bug with Unit Tests on Mojave: "The bundle couldn’t be loaded because it is damaged or missing necessary resources"
i was able to workaround this by reverting to the legacy build system for now to get the UI tests ru...
17
CocoaPods pod search AFNetWorking
Can you try removing search_index.json and run search command again? I'd be happy if you send the ou...
17
CocoaPods Signing for requires a development team. Select a development team in the Target Editor. in Xcode 8 and Swift 3. 🌈
I know it's a bit self explanatory but to make the project actually build again select a Development...
16
CocoaPods Playgrounds regression between CocoaPods 1.4.0 and CocoaPods 1.5.0
@dnkoutso The workaround suggested above (@litmanenPL) does resolve the issue 🌈 I've read and under...
15
CocoaPods 'Pod Spec Lint' failed validation
Confirmed this is the same as #8116 This worked and I was able to lint successfully Please remove In...
14
CocoaPods Current CocoaPods should be installable on Mojave without dependency upgrades
Here's an annotated transcript of my console session reproducing the problem I've also discovered th...
13
CocoaPods Pushing spec fails with Xcode 10 GM
Run gem install cocoapods --pre to install beta version 1.6.0.beta.1 fixes the issue for me ...
11
CocoaPods RuntimeError - [Xcodeproj] Unknown object version.
you are on a very old version of cocoapods please update to latest version and also gem update xcode...