Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

制作私有库有微信,支付宝SDK报上面错误,解决方法:

.podspec文件添加

s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }  #可不加
s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }  #必须

参考:

https://stackoverflow.com/questions/63607158/xcode-12-building-for-ios-simulator-but-linking-in-object-file-built-for-ios/64125194?r=SearchResults#64125194

 

131

Trying to get a large (and working on Xcode 11!) project building in Xcode 12 (beta 5) to prep for iOS 14. Codebase was previously Obj-C, but now contains both Obj-C and Swift, and uses pods that are Obj-C and/or Swift as well.

I have pulled the new beta of cocoapods with Xcode 12 support (currently 1.10.0.beta 2).

Pod install is successful. When I do a build, I get the following error on a pod framework:

"building for iOS Simulator, but linking in object file built for iOS, for architecture arm64"

When I go run lipo -info on the framework, it has: armv7s armv7 i386 x86_64 arm64.

Previously, the project had Valid Architectures set to: armv7, armv7s and arm64.

In Xcode 12, that setting goes away, as per Apple's documentation. Architectures is set to $(ARCHS_STANDARD). I have nothing set in excluded architectures.

Anyone have an idea of what may be going on here? I have not been able to reproduce this with a simpler project yet.

share  improve this question   
  • 1
    I'm getting the same thing on a link step of any 3rd party framework that's being manually included in the project. I'm curious if you find a solution. – SlashDevSlashGnoll Aug 27 at 17:41
  •  
    Have you solved this in the mean time? (mid september, still Xcode 12 beta 6) – epologee Sep 13 at 11:46
  • 1
    This is worked for me: stackoverflow.com/questions/24924809/… – Narendar Singh Saini Sep 23 at 10:12
  • 1
    I am getting building for iOS Simulator, but linking in object file built for macOS, for architecture x86_64 :( How to fix it? – Sazzad Hissain Khan Oct 1 at 13:56

22 Answers

168
 

Basically you have to exclude arm64 for simulator architecture both from your project and the Pod project,

  • To do that, navigate to Build Settings of your project and add Any iOS Simulator SDK with value arm64 inside Excluded Architecture.

    enter image description here

OR

  • If you are using custom XCConfig files, you can simply add this line for excluding simulator architecture.
EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64

Then

You have to do the same for the Pod project until all the cocoa pod vendors are done adding following in their Podspec.

s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }

You can manually add the Excluded Architechure in your Pod project's Build Settings, but it will be overwritten when you use pod install.

In place of this, you can add this snippet in your Podfile. It will write the neccessary Build Settings every time you run pod install

post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
    config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
  end
end
share  improve this answer   
  • 11
    wow, man! saved my day and possibly night! Thanks for such a detailed answer. – Josh Sep 18 at 11:49
  • 2
    The extra detail about CocoaPods here is nice. Note that without [sdk=iphonesimulator*] after EXCLUDED_ARCHS, XCode will fail to find your pods when building for an actual device since none of the pods will be built for arm64. – mwu Sep 22 at 17:34
  • 2
    Worked for me! Note that there is already a post_install do |installer| section in most Podfiles due to flipper. Paste the inner section installer.pods_project.build_configurations.each do |config| config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" endbehind the flipper_post_install(installer) line. – Ramon Vermeulen Sep 29 at 9:59 
  • 2
    I am getting building for iOS Simulator, but linking in object file built for macOS, for architecture x86_64. How to fix it? – Sazzad Hissain Khan Oct 1 at 13:56
  • 3
    This doesn't work for me. – user3335999 Oct 2 at 6:22
 
55

Found a solution!  https://developer.apple.com/forums/thread/657913

If you set excluded architectures for the simulator to arm64 it will compile.

excluding architectures for simulator

share  improve this answer   
  • 4
    I don't believe this is a solution. This creates a problem with the cocoapods post build step with the script they install. Pods/Target Support Files/Pods-All-Apps-XXX/Pods-All-Apps-XXX-frameworks.sh: line 141: ARCHS[@]: unbound variable This is in a method that is attempting to strip invalid architectures, so it still can't finish the build. Even then, excluding arm64 is a temporary fix that might get the sim to run, but won't fix the build problem. – btxios Aug 27 at 19:14 
  •  
    Fair enough, the issue I was having was with a manually linked library however it did not cause a problem with our pods we're using either. – SlashDevSlashGnoll Aug 31 at 12:55
  • 3
    I was testing on Release mode so I had to add it to Release too – MujtabaFR Sep 20 at 18:40
  •  
    I think we are back in the business after this post. thank you it helped. – JBarros35 Sep 21 at 8:19 
  • 1
    This doesn't work for me. – user3335999 Oct 2 at 6:22
32

Xcode 12, beta 6

The Valid Architectures build setting has been removed in Xcode 12. If you had values in this build setting, they're causing a problem and need to be removed.

I was able to "clear out" the VALID_ARCHS build setting by adding it back in as a User-Defined build setting (with no values), running the project (which failed), and then deleting the VALID_ARCHS build setting. After that, I was able to run on the simulator.

My Architectures build setting is Standard Architectures.

You can add a User-Defined Setting from the plus button in Build Settings:

User-Defined Setting

share  improve this answer   
  • 5
    This should be the accepted answer. Make sure the app project is selected not the Target. Otherwise, you won't be able to delete the VALID_ARCHS from Build Settings. :) – Bionicle Sep 5 at 7:55 
  • 1
    @trishcode Even after doing this i'm getting same error(xcode12 beta4), any work arounds – Sivakrishna Perla Sep 8 at 10:16 
  • 3
    @SivakrishnaPerla If you can open the project in Xcode 11, then you can see exactly which targets Valid Architectures is used on. You could even clear the setting in Xcode 11, and then try the project again in Xcode 12. If you still need a workaround and you're getting the error on an embedded framework, then SlashDevSlashGnoll's answer should work. If you need a workaround and you're getting the error on a Cocoapod, then exclude the arm64 architecture in the Podfile post install. – trishcode Sep 8 at 12:57 
  • 1
    @trishcode Thanks, Setting arm64 in excluded architecture and removing VALID_ARCHS worked. – Sivakrishna Perla Sep 8 at 13:35
  • 1
    If I remove VALID_ARCHS and add arm64 to Excluded architecture, I get this error - Check dependencies No architectures to compile for (ARCHS=arm64 x86_64, VALID_ARCHS=, EXCLUDED_ARCHS=( arm64 )). – nOOb iOS Sep 14 at 16:08
19

TL;DR;

Set "Build Active Architecture Only (ONLY_ACTIVE_ARCH)" to Yes for your libraries/apps, even for release mode.


While trying to identify the root cause of the issue I realized some fun facts about Xcode 12.

  1. Xcode 12 is actually the stepping stone for Apple Silicon which unfortunately is not yet available. But with that platform we are gonna get arm64 based macOS where simulators will also run on arm64 architecture unlike the present Intel based x86_64 architecture.

  2. Xcode usually depends on the "Run Destination" to build its libraries/apps. So when a simulator is chosen as the "Run Destination", it builds the app for available simulator architectures and when a device is chosen as the "Run Destination" it builds for the architecture that the device supports (arm*).

  3. xcodebuild, in the Xcode 12+ build system considers arm64 as a valid architecture for simulator. So when a simulator is chosen as the run destination, it can potentially try to compile/link your libs/apps against arm64 based simulators as well (not available yet). So it sends clang(++) some -target flag like arm64-apple-ios13.0-simulator in <architecture>-<os>-<sdk>-<platform> format and clang tries to build/link against arm64 based simulator that eventually fails on Intel based mac.

  4. But xcodebuild tries this only for Release builds. Why? Because, "Build Active Architecture Only (ONLY_ACTIVE_ARCH)" build settings is usually set to "No" for the "Release" configuration only. And that means xcodebuild will try to build all architectural variants of the libs/apps and for simulator that includes both x86_64 and arm64 now, since arm64 is available in Xcode 12+ for simulators to support Apple Silicon.

Simply putting, Xcode will fail to build your app anytime it tries the command line, xcodebuild, (which defaults to release build, see the general tab of your project setting) in release mode. So a simple workaround to this issue is to set "Build Active Architecture Only (ONLY_ACTIVE_ARCH)" to Yes in your libraries/apps, even for release mode.

enter image description here enter image description here

If the libraries are included as Pods and you have access to .podspec you can simply set:

spec.pod_target_xcconfig = { 'ONLY_ACTIVE_ARCH' => 'YES' }

spec.user_target_xcconfig = { 'ONLY_ACTIVE_ARCH' => 'YES' } # not recommended

I personally don't like the second line since pods shouldn't pollute the target project and it could be overridden in the target settings, itself. So it should be the responsibility of the consumer project to override the setting by some means.

However, if you don't have access to the .podspec, you can always update the settings during installation of the pods:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings["ONLY_ACTIVE_ARCH"] = "YES"
    end
  end
end

One thing I was concerned about that what will be the impact of this when we actually archive the libs/apps. During archiving apps usually take the "Release" configuration and since this will be creating a release build considering only the active architecture of the current run destination, with this approach, we may lose the slices for armv7, armv7s, etc from target build. However, I noticed the documentation says (highlighted in the attached picture) that this setting will be ignored when we choose "Generic iOS Device/Any Device" as the run destination, since it doesn't define any specific architecture. So I guess we should be good if we archive our app choosing that as a run destination.

share  improve this answer   
  • 6
    This is the first answer that improved my understanding of the problem, instead of just saying "change these three build settings and maybe it works". Thanks for the time you put in the write-up! – epologee Oct 1 at 13:43
  •  
    This is really a surprising change from Apple and costed me half a day to figure out that I feel Apple should compensate :). This is not a documented update (at least as I know of) and certainly going to affect everyone upgrading to Xcode 12. I only hope everybody finds their own way to get over with it once they know the basics. – Ayan Sengupta Oct 1 at 20:12
6

After upgrading to Xcode 12 I was still able to build for a real device, but not the simulator. The Podfile build was working only for the real device.

I deleted VALID_ARCHS under Build Settings > User-Defined and it worked! Bashing my head for some time before finding this.

share  improve this answer   
5

I believe I found the answer. Per the Xcode 12 beta 6 release notes:

"The Build Settings editor no longer includes the Valid Architectures build setting (VALID_ARCHS), and its use is discouraged. Instead, there is a new Excluded Architectures build setting (EXCLUDED_ARCHS). If a project includes VALID_ARCHS, the setting is displayed in the User-Defined section of the Build Settings editor. (15145028)"

I was able to resolve this issue by manually editing the project file (I could not figure out how to remove the item from the project file using Xcode) and removing all lines referring to VALID_ARCHS. After that, I am able to build for the simulator fine.

share  improve this answer   
  •  
    Using Xcode, VALID_ARCHS is in select Project (not Target) then `Build Setting -> User-Defined". select it and delete it. – Akshay Sep 19 at 4:58 
  •  
    This solution worked for me. The solution suggested by some others didn't work as just adding value 'arm64' to the 'Exclude Architecture' field started giving some 'File Permission' error for the generated .app file. – archeopetrix Sep 21 at 14:53
5

I solve problem by adding "arm64" in "Excluded Architectures" for both project target and pod target.

Xcode -> Target Project -> Build Setting -> Excluded Architectures > "arm64"

Xcode -> Pod Target -> Build Setting -> Excluded Architectures > "arm64"

share  improve this answer   
5

If you have trouble in Xcode 12 with simulators, not real device, yes you have to remove VALID_ARCHS settings because it's not supported anymore. Go to "builds settings", search "VALID_ARCHS" and remove the user-defined properties. Do it in every target you have.

Still, you may need to add a script at the bottom of your podfile to have pods compiling with the right architecture and deployment target :

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
      config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
     end
  end
end
share  improve this answer   
4

In you xxx.framework podspec file add follow config avoid pod package contains arm64 similator archs

s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
share  improve this answer   
  •  
    It worked! However this means that the Pod cannot be used in Apple Silicon based Macs? – tomacco Sep 30 at 6:26
  •  
    Is it confirmed @tomacco? – Fernando Reynoso Oct 1 at 17:02 
  • 1
    @FernandoReynoso I have just received an Developer Transition Kit, (ARM MacMini) will test and report later today – tomacco Oct 2 at 10:50
3

For Pod Developers In your Podspec add:

s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }

Then in your sample project Sample project files settings

See it working in this project

share  improve this answer   
2

Xcode 12

Removing VALID_ARCH from Build settings under User-Defined group work for me.

enter image description here

share  improve this answer   
1

The problem here are the Valid architectures in Xcode 11, open the project in Xcode 11 and change the Valid architectures value to $(ARCHS_STANDARD) for both your project, target and Pods, re-open the project in Xcode 12 and build

share  improve this answer   
1

Set the "Build Active Architecture Only"(ONLY_ACTIVE_ARCH) build setting to yes, xcode is asking for arm64 because of Silicon MAC architecture which is arm64.

arm64 has been added as simulator arch in Xcode12 to support Silicon MAC.

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/SDKSettings.json

share  improve this answer   
1

In my case: Xcode 12

I set empty values on EXCLUDED_ARCHS and set ONLY_ACTIVE_ARCH Debug = YES Release = NOProject's Build Setting

and I included this in my Podfile:

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
        end
    end
end

It runs on my Simulator iPhone 8 (iOS 12) and iPhone 11 Pro Max (iOS 14) and on my device iPhone 7 Plus (iOS 13.4)

share  improve this answer   
1

I was having issues building frameworks from the command line. My framework depends on other frameworks that were missing support for ARM-based simulators. I ended up excluding support for ARM-based simulators until I upgrade my dependencies.

I needed the EXCLUDED_ARCHS=arm64 flag when building the framework for simulators from CLI.

xcodebuild archive -project [project] -scheme [scheme] -destination "generic/platform=iOS Simulator" -archivePath "archives/[scheme]-iOS-Simulator" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES EXCLUDED_ARCHS=arm64
share  improve this answer   
1

On Build Settings search VALID_ARCH then press delete. This should work for me with Xcode 12.0.1

VALID_ARCH on build settings

share  improve this answer   
0

In my case:

I had 4 configurations(+ DebugQa and ReleaseQa) Cocoapods is used as a dependency Manager

For Debug, I gathered on the device and in the simulator, and on qa only on the device.

It helped to set BuildActiveArchitecture to yes in PodsProject

share  improve this answer   
0

In my case I was trying to run on an watchOS 7 simulator in Relese mode but the iOS 14 simulator was in Debug mode.

So simply putting both sims in Debug/Release mode solved the problem for me!

share  improve this answer   
0

For me the following setting worked:

Build Settings >> Excluded Architectures

added "arm64" to both Release and Debug mode for "Any iOS Simulator SDK" option.

enter image description here

share  improve this answer   
0

Switch Build Configuration back to Debug mode or turn on Build Active Architecture Only for both Debug and Release mode. The reason is your library/framework doesn't support new Simulator architecture ARM64 (run on Mac with Apple Silicon processor)

share  improve this answer   
0

Add line "arm64" (without quotes) to path: Xcode -> Project -> Build settings -> Architectures -> Excluded architectures Also, do the same for Pods. In both cases for both debug and release fields.

or in detail...

Errors mentioned here while deploying to simulator using Xcode 12 are also one of the things which have affected me. Just right-clicking on each of my projects and showing in finder, opening the .xcodeproj in Atom, then going through the .pbxproj and removing all of the VALIDARCHS settings. This was is what got it working for me. Tried a few of the other suggestions (excluding arm64, Build Active Architecture Only) which seemed to get my build further but ultimately leave me at another error. Having VALIDARCH settings lying around is probably the best thing to check for first.

share  improve this answer   
-1

To get this working for Calabash automated tests

There is a pull request up to fix the issue of xcode 12 not working with calabashhttps://github.com/calabash/run_loop/pull/757

A temporary solution is to use this WIP branch, although it is not great to have to use this as it is a draft PR. Xcode 12 support for Calabash will hopefully come in the future.

Change in your Gemfile

gem "run_loop"

to

gem 'run_loop', git: 'https://github.com/calabash/run_loop.git', branch: 'xcode_14_support'
 
posted @ 2020-10-13 19:01  MaxWell_dzl  阅读(6385)  评论(0编辑  收藏  举报