1. 程式人生 > 實用技巧 >Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

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.

shareimprove this question editedSep 2 at 9:12 Abhishek Bedi 3,61511 gold badge2323 silver badges5454 bronze badges askedAug 26 at 23:40 btxios 1,46322 gold badges66 silver badges77 bronze badges
  • 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.–SlashDevSlashGnollAug 27 at 17:41
  • Have you solved this in the mean time? (mid september, still Xcode 12 beta 6)–epologeeSep 13 at 11:46
  • 1 This is worked for me:stackoverflow.com/questions/24924809/…Narendar Singh SainiSep 23 at 10:12
  • 1 I am gettingbuilding for iOS Simulator, but linking in object file built for macOS, for architecture x86_64:( How to fix it?–Sazzad Hissain KhanOct 1 at 13:56
add a comment

22 Answers

ActiveOldestVotes 168

Basically you have to excludearm64for simulator architecture both from your project and the Pod project,

  • To do that, navigate toBuild Settingsof your project and addAny iOS Simulator SDKwith valuearm64insideExcluded Architecture.

OR

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

Then

You have to do the same for thePod projectuntil all the cocoa pod vendors are done adding following in theirPodspec.

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

You can manually add theExcluded Architechurein your Pod project'sBuild Settings, but it will be overwritten when you usepod install.

In place of this, you can add this snippet in yourPodfile. It will write the neccessaryBuild Settingsevery time you runpod install

post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
    config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
  end
end
shareimprove this answer editedSep 25 at 9:05 fl034 3,86722 gold badges2424 silver badges3737 bronze badges answeredSep 18 at 11:41 Amit Samant 1,95511 gold badge44 silver badges1010 bronze badges
  • 11 wow, man! saved my day and possibly night! Thanks for such a detailed answer.–JoshSep 18 at 11:49
  • 2 The extra detail about CocoaPods here is nice. Note that without[sdk=iphonesimulator*]afterEXCLUDED_ARCHS, XCode will fail to find your pods when building for an actual device since none of the pods will be built for arm64.–mwuSep 22 at 17:34
  • 2 Worked for me! Note that there is already apost_install do |installer|section in most Podfiles due to flipper. Paste the inner sectioninstaller.pods_project.build_configurations.each do |config| config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" endbehind theflipper_post_install(installer)line.–Ramon VermeulenSep 29 at 9:59
  • 2 I am gettingbuilding for iOS Simulator, but linking in object file built for macOS, for architecture x86_64. How to fix it?–Sazzad Hissain KhanOct 1 at 13:56
  • 3 This doesn't work for me.–user3335999Oct 2 at 6:22
show8more comments 55

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

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

shareimprove this answer answeredAug 27 at 18:58 SlashDevSlashGnoll 1,12266 silver badges1414 bronze badges
  • 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.–btxiosAug 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.–SlashDevSlashGnollAug 31 at 12:55
  • 3 I was testing onReleasemode so I had to add it to Release too–MujtabaFRSep 20 at 18:40
  • I think we are back in the business after this post. thank you it helped.–JBarros35Sep 21 at 8:19
  • 1 This doesn't work for me.–user3335999Oct 2 at 6:22
add a comment 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:

shareimprove this answer editedSep 18 at 14:33 answeredSep 2 at 21:50 trishcode 1,1911111 silver badges2020 bronze badges
  • 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. :)–BionicleSep 5 at 7:55
  • 1 @trishcode Even after doing this i'm getting same error(xcode12 beta4), any work arounds–Sivakrishna PerlaSep 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.–trishcodeSep 8 at 12:57
  • 1 @trishcode Thanks, Setting arm64 in excluded architecture and removing VALID_ARCHS worked.–Sivakrishna PerlaSep 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 iOSSep 14 at 16:08
show6more comments 19

TL;DR;

Set "Build Active Architecture Only (ONLY_ACTIVE_ARCH)" toYesfor your libraries/apps, even forreleasemode.


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 considersarm64as 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 againstarm64based simulators as well (not available yet). So it sendsclang(++)some -target flag likearm64-apple-ios13.0-simulatorin <architecture>-<os>-<sdk>-<platform> format and clang tries to build/link against arm64 based simulator that eventually fails on Intel based mac.

  4. Butxcodebuildtries this only forReleasebuilds. Why? Because, "Build Active Architecture Only (ONLY_ACTIVE_ARCH)" build settings is usually set to "No" for the "Release" configuration only. And that meansxcodebuildwill try to build all architectural variants of the libs/apps and for simulator that includes bothx86_64andarm64now, sincearm64is 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)" toYesin your libraries/apps, even for release mode.

If the libraries are included as Pods and you have access to.podspecyou 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 sincepods shouldn't pollute the target projectand 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.

shareimprove this answer editedOct 3 at 3:46 answeredSep 30 at 14:33 Ayan Sengupta 2,4251919 silver badges3737 bronze badges
  • 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!–epologeeOct 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 SenguptaOct 1 at 20:12
add a comment 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.

shareimprove this answer answeredSep 17 at 4:54 Navigator 8166 bronze badges add a comment 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.

shareimprove this answer answeredSep 1 at 21:12 btxios 1,46322 gold badges66 silver badges77 bronze badges
  • Using Xcode, VALID_ARCHS is in select Project (not Target) then `Build Setting -> User-Defined". select it and delete it.–AkshaySep 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.–archeopetrixSep 21 at 14:53
add a comment 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"

shareimprove this answer answeredSep 17 at 15:14 Vader 5944 bronze badges add a comment 5

If you have trouble in Xcode 12 with simulators, not real device, yes you have toremove VALID_ARCHSsettings because it's not supported anymore. Go to "builds settings", search "VALID_ARCHS" andremovethe user-defined properties. Do it inevery targetyou 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
shareimprove this answer answeredSep 24 at 9:14 Medhi 26922 silver badges55 bronze badges add a comment 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' }
shareimprove this answer answeredSep 18 at 11:04 jiawei wang 4111 bronze badge
  • It worked! However this means that the Pod cannot be used in Apple Silicon based Macs?–tomaccoSep 30 at 6:26
  • Is it confirmed @tomacco?–Fernando ReynosoOct 1 at 17:02
  • 1 @FernandoReynoso I have just received an Developer Transition Kit, (ARM MacMini) will test and report later today–tomaccoOct 2 at 10:50
add a comment 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

See it workingin this project

shareimprove this answer answeredSep 24 at 14:43 Pacu 1,9671919 silver badges3232 bronze badges add a comment 2

Xcode 12

RemovingVALID_ARCHfromBuild settingsunderUser-Definedgroup work for me.

shareimprove this answer answeredSep 24 at 6:58 Pratik Sodha 2,77111 gold badge1414 silver badges3232 bronze badges add a comment 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

shareimprove this answer answeredSep 17 at 10:40 user4478383 29822 silver badges1010 bronze badges add a comment 1

Set the"Build Active Architecture Only"(ONLY_ACTIVE_ARCH)build setting to yes,xcodeis 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

shareimprove this answer editedSep 30 at 8:20 Dilan 1,98955 gold badges1313 silver badges2020 bronze badges answeredSep 29 at 18:05 Aravind 1122 bronze badges add a comment 1

In my case: Xcode 12

I set empty values onEXCLUDED_ARCHSand setONLY_ACTIVE_ARCHDebug =YESRelease =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)

shareimprove this answer editedOct 2 at 7:04 answeredSep 29 at 5:43 mitchy_dev 1122 bronze badges add a comment 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 theEXCLUDED_ARCHS=arm64flag 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
shareimprove this answer answeredOct 6 at 13:32 inder_gt 16533 silver badges77 bronze badges add a comment 1

OnBuild SettingssearchVALID_ARCHthen pressdelete. This should work for me with Xcode 12.0.1

shareimprove this answer answeredOct 8 at 17:30 Cuong Lam 1,72611 gold badge1616 silver badges1717 bronze badges add a comment 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

shareimprove this answer answeredSep 20 at 9:08 voragomod 4711 silver badge77 bronze badges add a comment 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!

shareimprove this answer answeredSep 21 at 8:12 Cosmin 5,23333 gold badges2323 silver badges2727 bronze badges add a comment 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.

shareimprove this answer answeredSep 30 at 12:58 Raghav 5,73733 gold badges4848 silver badges7373 bronze badges add a comment 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)

shareimprove this answer answeredOct 5 at 22:52 Tran Anh Khoa 3111 bronze badge add a comment 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.

shareimprove this answer edited2 days ago Dharman 16.9k1414 gold badges4343 silver badges9595 bronze badges answered2 days ago Sohaib Aslam 65599 silver badges2020 bronze badges add a comment -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'