117

I have my custom framework and it works properly in XCode 10. I rebuild it in XCode 11 beta 3, then integrated into the app, and get the following error:

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

Are there some changes I have to make in "valid architectures" in the framework project?

Updated: I can't pick any answer as a correct one as the framework in my case was really tiny (one class, a few methods) and almost not in use, so I decided to get rid of it and move these a few methods into main project.

Oleshko
  • 2,923
  • 4
  • 17
  • 25

24 Answers24

55

To solve this issue I had to create a fat library of my custom framework again using xcode 11 tools.

To do that I did the following:

1) Build YourCustomFramework target for iOS simulator and extract framework from products folder on your desktop.

Xcode⁩ ▸ ⁨DerivedData⁩ ▸ ⁨Your Project ▸ ⁨Build⁩ ▸ ⁨Products⁩ ▸ ⁨Release-iphonesimulator

2) Build YourCustomFramework target for Generic iOS Device and extract framework from products folder on your desktop.

Xcode⁩ ▸ ⁨DerivedData⁩ ▸ ⁨Your Project ▸ ⁨Build⁩ ▸ ⁨Products⁩ ▸ ⁨Release-iphoneos⁩

3) Rename the simulator generated framework to YourCustomFramework-sim.framework so that it is distinguishable later.

4) Use the lipo command to combine both binaries into a single fat binary file. (cd to your desktop or wherever your custom framework file is located)

$lipo -create ./YourCustomFramework-sim.framework/YourCustomFramework ./YourCustomFramework.framework/YourCustomFramework -output ./YourCustomFramework

5) Copy YourCustomFramework binary file created in above step and replace it with the binary in YourCustomFramework.framework folder.

6) From folder

YourCustomFramework-sim.framework/Modules/YourCustomFramework.swiftmodule/

copy all of the modules and paste them to

YourCustomFramework.framework/Modules/YourCustomFramework.swiftmodule/

This should solve your issue.

willhess
  • 1,334
  • 13
  • 14
54

Swift 5.0-5.1, Xcode 11
Open Xcode, <your project>, Build Settings, Build Active Architecture Only and change to <NO> for Debug and Release. Architectures set/leave in Standard Architecture -$(ARCHS_STANDARD), important is next step:
Valid Architecture: armv7, armv7s, arm64, arm64e, ADD here x86_64 and if you need add i386 for Debug and Release. (String: armv7, armv7s, arm64, arm64e, x86_64)

Choose any simulator in your simulator list and BUILT IT. DONE. 

I hope it is works for you.


Description of Architecture:

armv64: iPhoneX, iPhone 5s-8, iPad Air — iPad Pro

armv7 : iPhone3Gs-5c, iPad WIFI(4th gen)

armv6 : iPhone — iPhone3G

-the above if for real devices

i386 : 32-bit simulator

x86_64 : 64-bit simulator

Vjardel
  • 1,065
  • 1
  • 13
  • 28
Serg Fugol
  • 677
  • 5
  • 4
  • 4
    Sorry, what is 'set/leave', must I delete 'Standard Architecture -$(ARCHS_STANDART)'? thanks – Álvaro Agüero Nov 29 '19 at 17:15
  • @ÁlvaroAgüero, "set/leave" expands to set the value in Build Settings, or leave it if it's already "$(ARCHS_STANDARD)" ... note the typo "STANDARD", not "STANDART". – groundh0g Dec 10 '19 at 11:57
  • 21
    I add x86_64 but still get the same error "Could not find the module for target 'x86_64-apple-ios-simulator'" – Md Imran Choudhury May 27 '20 at 10:07
  • 23
    Valid architectures has been removed for swift 12 – Michael Montalbano Sep 23 '20 at 18:50
  • 6
    @MichaelMontalbano, I was able to add VALID_ARCHS as a user defined setting and set it equal to the following, and it worked for me in sim and on device: `$(ARCHS_STANDARD) x86_64 i386 ` – agrippa Nov 20 '20 at 07:22
  • @agrippa Doesn't work. I have add VALID_ARCHS. – Mitul Marsoniya Feb 02 '21 at 19:17
  • 5
    I followed your steps... I have added `x86_64` and `x86_64-ios-simulator` in both my SDK and project, but no use i got this error.`Could not find module 'BlazeSdk' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios` . How to resolve this error in Xcode 12.2?. I want to run in iPad simulators. – Naresh Sep 22 '21 at 13:37
  • 1
    How should I set VALID_ARCHS setting to packages which are added to project via swift package manager? – salihtopcu Jul 17 '22 at 19:08
47

enter image description here

This is because all your library are not flexible with m1 chip. so right click on xcode, get info and tick open as rosetta. open your project, clean and build. Finally, run your project as before :D

Amrit Giri
  • 727
  • 5
  • 6
  • 53
    this is a hack, not a solution – Dani Pralea Apr 02 '21 at 11:06
  • 5
    It is a solution if you work on a large project where your personal environment should not affect the project config, which, in tern, can be less flexible and agile. – OlgaVogue Apr 02 '21 at 20:51
  • 4
    this is the answer if this getting from third-party library on m1 chip macbook – isaman kumara Jun 04 '21 at 16:32
  • 4
    hacky or not, after having two libraries that couldn't find an architecture solution to agree on.. I'm pretty happy to be able to get my work done with this. – Logan Feb 16 '22 at 19:03
  • still doesn't worked thou. i run via flutter run – cahyowhy Mar 05 '22 at 09:34
  • 2
    I think this should be the most acceptable answer since the root problem is coming from a framework not compilable with m1. To fix this, make it compilable for m1. To run this, open as rosetta ! – Pep Michael904 Aug 16 '22 at 12:49
  • I believe this is a hack not a solution. I encountered this problem with an SPM package, which does't even specify platform, it is just plain swift code. There is no way that package is not compatible with m1. Given that normally launching XCode in m1 without rosetta CAN indeed build and run for simulator, I believe we are not supposed to run it with rosetta. Adding User-Defined VALID_ARCHS works. – Ricky Mo Mar 17 '23 at 02:54
  • Does this solution work Xcode 14.3? – Aji Saputra Raka Siwi Mar 27 '23 at 10:17
43

I have added two architectures i386 and x86_64. And set Yes to "Build Active Architecture Only". It works for me to build on every simulator devices.

enter image description here

For the XCode-12 Valid Architectures has been moved under User-Defined option at the very bottom as VALID_ARCHS

AshWinee Dhakad
  • 671
  • 7
  • 11
  • 3
    I was facing with this issue for days, but adding these architectures solve the problem. – fdlr Sep 22 '20 at 07:43
  • 12
    in Xcode 12, VALID_ARCHS is available under User Defined settings – Mohan Sep 23 '20 at 05:49
  • 9
    VALID_ARCHS is the only thing that worked for me in xcode 12. A User Defined Setting can be made by clicking the + icon in the subtitle bar in your Project Target Build Settings tab. This took far too long to crack, thanks for saving my life guys! – agrippa Sep 28 '20 at 16:58
  • 2
    Despite allowing me to test the Release build on the Simulator just as I wanted, unfortunately this fix made my ipa NOT downloadable and in some cases NOT installable from Test Flight, though its upload was successful. I needed a very quick solution, so I just reverted the changes in `project.pbxproj`, and the next ipa was working again as expected. I didn't have time to test deeper and see what exact part caused the issue – Massimo Baldrighi Sep 28 '20 at 18:42
  • As a further note, it ended up needing to be the following instead of just listing them as I did originally and what was done in the OP: `$(ARCHS_STANDARD) x86_64 i386 ` – agrippa Nov 20 '20 at 07:21
  • I followed your steps... I have added `x86_64` and `x86_64-ios-simulator` in both my SDK and project, but no use i got this error.`Could not find module 'BlazeSdk' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios` . How to resolve this error in Xcode 12.2?. I want to run in iPad simulators. – Naresh Sep 22 '21 at 13:37
  • @iOS, Are you using intel based mac or M1? – AshWinee Dhakad Sep 29 '21 at 21:48
  • @ AshWinee Dhakad, Yes, i'm using `Intel Iris Plus Graphics 655 1536 MB` MacBook Pro. Can you help how to resolve this issue? – Naresh Sep 30 '21 at 06:36
  • Did they move valid architectures? I dont see any in the latest xcode. Nothing is below supported platforms – chitgoks Oct 10 '22 at 13:29
  • @chitgoks just check under build settings, the first dropdown is Architecture, default is arm64, you can add more manually. I am using XCode 14.0 – AshWinee Dhakad Oct 18 '22 at 12:06
  • Setting buildActiveArchitecturesOnly worked when face this error after installing dropDown Menu Pod – Ramesh Sanghar May 05 '23 at 11:23
43

I encountered this issue on my M1 MacBook.

To solve this I've added to following lines to my host app Podfile:

post_install do |installer_representation|
    installer_representation.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
            config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
        end
    end
end

Edit: Adding this line as well helped with runtime issues:

config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
Bob Ross
  • 756
  • 6
  • 13
  • I removed all libraries of SPM, and added pods.. and set ONLY_ACTIVE_ARCH to NO. The pods are not XCFramework, make problems. – Brownsoo Han Sep 18 '21 at 16:19
  • As per written it looks like M1 System have issue but if we make changes for intel system then also it will be fine. please let me know.... – Sudarshan Thorve Jun 14 '22 at 05:21
26

This is all I needed in my Podfile:

post_install do |pi|
  pi.pods_project.targets.each do |t|
    t.build_configurations.each do |config|
      config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
    end
  end
end
gngrwzrd
  • 5,902
  • 4
  • 43
  • 56
  • 1
    This worked for XCode 14 on M1 – Vincent Gigandet Oct 30 '22 at 07:49
  • This solution also works for me. (XCode 14 - M1). Note: Tested with XCode 14 - Intel also works. – IKQ Nov 25 '22 at 10:45
  • This is the only solution worked, thanks man, In short, the code snippet sets the ONLY_ACTIVE_ARCH build setting to 'NO' for each build configuration in your Xcode project. This ensures that all required architectures are built, even if they are not the active architecture for the current target. It can help resolve issues related to missing architectures or compatibility with certain frameworks or dependencies. – Lavkant Kachhwaha Jun 15 '23 at 17:17
16

Please check your Scheme be sure to run correct scheme.

And then you should open XCode > -Your Main Target- > Build Active Architecture Only and set 'NO' to build on the all architectures.

Options:

YES - If set to yes, then Xcode will detect the device that is connected, and determine the architecture, and build on just that architecture alone.

NO - If set to no, then it will build on all the architectures.

emrcftci
  • 3,355
  • 3
  • 21
  • 35
  • 7
    This does not solve if the framework was built without the x86 architecture in the first place. An error will still be thrown when trying to build with a simulator. – willhess Oct 01 '19 at 20:18
  • Use full information, But I followed your steps... I have updated into `NO`, but no use. How to resolve this error in Xcode 12.2?. I want to run in iPad simulators. – Naresh Sep 22 '21 at 13:40
10

For all pods on mac M1 chip you need to add 'x86_64-apple-ios-simulator' support in architectures in build setting. So process will be like,

  1. go to pods, select that the error target add x86_64-apple-ios-simulator in it. enter image description here

  2. Set "build active architecture". to No in pods specific target.

enter image description here

It will solve this problem. More in project setting. you can set "build active architecture" according to your requirement.

  • 3
    I followed your steps... I have added `x86_64` and `x86_64-ios-simulator` in both my SDK and project, but no use i got this error.`Could not find module 'BlazeSdk' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios` . How to resolve this error in Xcode 12.2?. I want to run in iPad simulators. – Naresh Sep 22 '21 at 13:34
  • 1
    How can we solve that for a package which was build using SPM ? – Waqas Mar 20 '23 at 11:29
9

At this time i am using xcode 12.5

For this i have edited User-Defined option at the very bottom with VALID_ARCHS

Select the target and go to Build Setting

Click the plus icon and you will see

enter image description here

Add VALID_ARCHS and $(ARCHS_STANDARD) value

or you can use -> armv7, armv7s, arm64, arm64e, x86_64, i386

enter image description here

Wasi Sadman
  • 1,382
  • 1
  • 15
  • 27
  • 7
    I followed your steps... I have added `x86_64` and `x86_64-ios-simulator` in both my SDK and project, but no use i got this error.`Could not find module 'BlazeSdk' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios` . How to resolve this error in Xcode 12.2?. I want to run in iPad simulators. – Naresh Sep 22 '21 at 13:33
  • yes.. it did worked.. – Sathya Baman Sep 24 '21 at 04:12
8

For the new M1 Mac with Xcode 12 I encountered the same issue. I was able to solve it by setting Build Active Architecture Only = 'Yes' and adding VALID_ARCHS = arm64 armv7 arm64-ios-simulator (essentially excluding x86_64 and x86_64-ios-simulator architecture) in the Build Settings.

Siddharth Kamaria
  • 2,448
  • 2
  • 17
  • 37
  • 3
    I followed your steps... I have added `x86_64` and `x86_64-ios-simulator` in both my SDK and project, but no use i got this error.`Could not find module 'BlazeSdk' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios` . How to resolve this error in Xcode 12.2?. I want to run in iPad simulators. – Naresh Sep 22 '21 at 11:56
  • @Naresh I have the same issue, do you found how to solve it? – Serhii Didanov Apr 19 '22 at 14:26
  • @Sergey Didanov, no – Naresh Apr 19 '22 at 15:18
  • 1
    @SergeyDidanov Did you try excluding Intel-based architectures (`x86_64` and `x86_64-ios-simulator`) from everywhere? My answer was specific to Apple Silicon Macs. – Siddharth Kamaria Apr 22 '22 at 06:37
  • 2
    This worked for me. In my project I am using `GoogleMaps-SDK` via CocoaPods that forces me to set `Excluded Architectures` to `Any iOS Simulator SDK: arm64` (to be able to run the project in the Simulator) which in turn another Library I am using via SPM did'nt like. – nayooti Aug 19 '22 at 15:58
4

That error means your custom framework has been built for any ios device (an actual device) and you are trying to use this custom framework on a simulator where your app is being tested.
The solution is very simple. Just rebuild your custom framwork for simulator you want to test it out(e.g. Iphone 13 simulator) not for 'Any iOS Device'. And replace the old framework with the newly compiled framework.

Junho Lee
  • 198
  • 1
  • 10
2

I had to set 'Build Active Architecture Only' from Debug:Yes/Release:No to Debug:No/Release:No for any Pod target showing the error

'Could not find module 'PODNAME' for target 'x86_64-apple-ios-simulator';'

where PODNAME is the pod throwing the error when you compile.

brian.clear
  • 5,277
  • 2
  • 41
  • 62
2

I was facing this issue for RxSwift while running unit tests. Changing the build settings of Pods project and setting the Build Active Architecture Only to No, fixed the issue for me enter image description here

Axel Guilmin
  • 11,454
  • 9
  • 54
  • 64
Pranav Pravakar
  • 205
  • 3
  • 7
1

Delete your pods and install pods with this command "arch -x86_64" pod install

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Akshu
  • 11
  • 2
1

Set the 'Build Active Architecture Only' to 'No'. Please look at the image below.

enter image description here

Shubham Goel
  • 1,962
  • 17
  • 25
1

For Macbook with M1, XCode 14.3, It worked after i changed destination architecture to "Show Rossetta Destinations"

Product -> Destination -> Destination Architectures -> Show Rossetta Architectures

enter image description here

May be this is hack. Hope this helps to fix this issue quickly.

Dhaval Bhimani
  • 980
  • 1
  • 13
  • 24
0

Alternative Solution

This question is actually about Creating Custom Framework. Even years after posting, people still visiting the page fixing similar issues. I think we need to head up for other solutions as well.

After Xcode 11 now Xcode fully supports using and creating binary frameworks in Swift. Simultaneously support devices and Simulator with the new XCFramework bundle type. XCFrameworks support the binary distribution of Swift and C-based code (C, C++, Objective-C). A single XCFramework can contain a variant for the simulator, and for the device. This means you can ship slices for any of the architectures, including the simulator, any Apple OS, and even separate slices for UIKit and AppKit apps.

You can check the repo if you're interesting the using a library for creating Custom Framework.

MGY
  • 7,245
  • 5
  • 41
  • 74
0

if you think @willhess answer is hard you can use this script

open Build Phases -> click plus button -> New Run Script Phase and add below code

UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal

mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

cp -a "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" 
"${UNIVERSAL_OUTPUTFOLDER}/"


SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/."
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule"
fi


lipo -create -output 
"${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" 
"${BUILD_DIR}/${CONFIGURATION}- 
iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" 
"${BUILD_DIR}/${CONFIGURATION}- 
iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"


cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" 
"${PROJECT_DIR}"

open "${PROJECT_DIR}"

Then build simulator and any ios device, your project folder will be open and your fat framework will be there

Tolga İskender
  • 158
  • 2
  • 14
  • I followed your steps... but not use. How to resolve this error in Xcode 12.2?. I want to run in iPad simulators. – Naresh Sep 22 '21 at 13:33
  • i also tried on xcode 12.2 and in your framework file should be "Modules" file and inside it "frameworkname.swiftmodule" ,in "frameworkname.swiftmodule" should be x86_64 and arm64 files – Tolga İskender Sep 23 '21 at 14:06
  • Tolga İskender, can you provide any tutorial link for me... either video or any type. – Naresh Sep 24 '21 at 05:40
  • you can watch this guy https://www.youtube.com/watch?v=90Tp3WtQp40&ab_channel=iOSCoderAbhimanyuDaspan – Tolga İskender Sep 24 '21 at 14:13
0

in my case show this alert because Pod 'MessageKit', '~> 3.3.0' have this problem but just change Deployment info To iOS 13 For MessageKit All Done

0

Since Valid Archs isn't available for Xcode 12, you will create a user defined setting by hitting + and typing VALID_ARCHS with the x86_64 and additional architectures.

0

In my case, I have added test target after the pod init, install etc.. And I saw, adding test target block in podfile solved my problem.

Example;

target 'SampleProject' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for SampleProject

  target 'SampleProjectTests' do
    inherit! :search_paths
    # Pods for testing
  end
end
0

Only this worked for me. Paste this code at the bottom of the podfile and run pod install.

post_install do |installer|   installer.pods_project.build_configurations.each do |config|
    config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "x86_64"   
end 
end
Naval Hasan
  • 1,226
  • 1
  • 13
  • 18
-1

You need to change the Architecture settings for both Project and Pods project files.

Select project settings then write Architecture in the search bar. After that change the `Build Active Architecture Only" to false NO for all targets.

Then add x86_64-apple-ios-simulator to the Architectures propriety.

You need to do the same for the Pods project setting.

Amjad Tubasi
  • 384
  • 5
  • 7
-7

For me it was a setting missing. In Xcode go to: File->Workspace Settings . In Build System change it to "Legacy Build system".

Run it again and copy the new Framework