Which architectures are used when I compile something for iOS? - ios

I try to understand the different architectures for iOS, and when I need which.
I have a Hello World example. Is my assumption correct that, if I run it in the Xcode Simulator, I need to compile everything including my dependencies for x64 (because it's running on my computer).
And for my attached iPhone it's getting compiled for only that architecture. And for Generic iPhones my example will be a multiarchitecture app (arm64 arm64 armv7 armv7e) so it can run on a variety of architectures. Is that correct?
Thanks for your insight.
P.S. So if my example links foo.a, but foo.a is just arm64 arm64 armv7 armv7e but not x64, I could compile my app for iPhones but not run it in my simulator

This is essentially correct although you have two arm64 listed above; it should be arm64 and arm64e.
As to what architectures get built, it depends on the setting "Build Active Architecture Only". The typical Debug config has this set to Yes, so it only builds for the architecture of the device that you're targeting.
A Release config has this set to No, so it compiles for all architectures specified in "Architectures", which usually $(ARCHS_STANDARD), i.e., the architectures you listed.
As to your PS, you are correct that a .a file with only ARM archs could not be linked to a Simulator target.

Related

Why does Xcode build for arm64 even when excluded?

I am trying to solve a problem related to Xcode 12, building for iOS Simulator, but linking in an object file built for iOS, for architecture 'arm64'
As an experiment, I wanted to see if I could configure one of my frameworks to only build x86_64 for all cases.
Here is my config:
You can see I have overridden the architectures to be x86_64 and I am excluding arm64. I am also only building active architectures only. There is no way that arm64 should ever be considered during a build.
And yet...
Here is the output of a build the very next moment. It's tons of source files that indicate they are still being compiled for arm64.
Can anyone explain this discrepancy? I am running the latest Xcode, 13.2.1, on a new M1 Max laptop.

How to switch flutter plugin architecture from arm64 to armv7

When I tried to decrease my flutter app's deployment target (iOS 12 to 9.3), I received this error when running flutter build ios:
=== BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Release ===
fatal error: lipo: -extract armv7 specified but fat file:
/Users/xxx/development/myapp/build/ios/Release-iphoneos/Runner.app/Frameworks/flutter_webview_plugin.framework/flutter_webview_plugin does not contain that architecture
Failed to extract armv7 for /Users/xxx/development/myapp/build/ios/Release-iphoneos/Runner.app/Frameworks/flutter_webview_plugin.framework/flutter_webview_plugin. Running
lipo -info:
Architectures in the fat file: /Users/xxx/development/myapp/build/ios/Release-iphoneos/Runner.app/Frameworks/flutter_webview_plugin.framework/flutter_webview_plugin are:
arm64
I am unable to find any information on how to change the architecture in question - can I even do this? Or is this something the plugin developer has to build in?
I would like to be able to run the app with the lowest possible iOS version for maximum compatibility.
In the project build settings, there is a section called Architectures, there you can set the ones you need. As far as I know, the latest iPhones need to use arm64, but in my picture you can see that I'm also set as valid armv7, that seems to be your problem.

armv7 not included in build

Both my Target and Project Build Settings are set to arm64 armv7 armv7s as the valid architectures.
Architectures: Standard architectures (armv7, arm64) - $
Valid Architectures: arm64 armv7 armv7s
When I archive and upload the build, iTunes Connect classifies it as only arm64. Under "Supported Architectures", iTunes Connect shows only arm64. This makes it so my app is not available to older devices (iPhone 5, iPad 2, iPad Mini 1, etc)
Has anybody ever come across this before? I'm supporting armv7 in Xcode settings, but that support is not being included in the build I am archiving.
Even though this topic already has it's accepted answer, this one is not true in any case.
There can be situations, in which your app has all the known architectures as valid architectures, has Build Active Architecture Only to NO for Release and still getting this issue.
The reason is: If your deployment target is iOS >= 11, then this will run on devices starting with iPhone 5s only. iPhone 5s is the first arm64 device. Hence XCode (at least in version 10) does NOT include anything else than arm64, even though you have all the settings made as suggested.
Usually this is not a problem, but it can lead to the "Too many symbols" issue, if you are using Pods, which come with binaries for architectures < arm64. Those will have symbols for armv7, even though your upload does not have a binary for armv7.
So it is suggested to fight this by altering the PodFile and include only symbols for arm64.
I suspect you are building the active architecture only.
To fix this set Build Active Architecture Only to NO for Release configuration.

iOS architectures vs Valid Architectures and repercussions of settings

I have a library that is not 64 bit ready, so I removed arm64 from "architectures". I was then able to use the application on 64 bit platforms in the simulator. (It didn't work until I made that change. It would just crash)
When I was going to create an archive for my app to send to the store, I got the following error:
(null): File is universal (3 slices) but does not contain a(n) armv7s slice: /Users/cmuench/Desktop/PHP-Point-Of-Sale-Repos/PHP-Point-Of-Sale-iOS/PHP Point Of Sale/starSDK/StarIO.framework/StarIO file '/Users/cmuench/Desktop/PHP-Point-Of-Sale-Repos/PHP-Point-Of-Sale-iOS/PHP Point Of Sale/starSDK/StarIO.framework/StarIO' for architecture armv7s
I think this is because the another framework I use I am using for a receipt printer doesn't support armv7s.
3 questions:
Why was it able to work in debugging environment but then fail when creating an archive? The only way I could get the archive to work was by removing armv7s from "valid architectures"
Will my application work on newer hardware that uses the armv7s platform? (I don't have the newer hardware)
What is the difference between "architectures" and "Valid Architectures" in build settings?
In the simulator, the architecture is i386 not armv7 or armv7s. You would only get this error if you tried to run a debug session in a iOS device which had an armv7s chip.
Yes, arm64 and armv7s will run armv7 binaries.
Build Setting Reference describes all the build settings.
ARCHS (Architectures): Space-separated list of identifiers. Specifies the architectures (ABIs, processor models) to which the binary is targeted. When this build setting specifies more than one architecture, the generated binary may contain object code for each of the specified architectures.
VALID_ARCHS (Valid Architectures): Space-separated list of identifiers. Specifies the architectures for which the binary may be built. During the build, this list is intersected with the value of ARCHS build setting; the resulting list specifies the architectures the binary can run on. If the resulting architecture list is empty, the target generates no binary.

SQLCipher for iOS, running on armv7s and armv devices

So I've had some headaches today trying to solve this one. I have SQLCipher integrated into an iOS application and before I go further, here are my architecture build settings:
As I understand it, this should only build for an armv7s device (such as a iPhone 5), and when trying to run on a armv7 device I quite rightly get this error:
So I try changing the project's build architecture to Standard (armv7s, armv7) and build. This still runs as expected on the armv7s device, but on a armv7 device I get these linking errors:
So naturally I check out the build settings for the library throwing these errors, and they both have armv7 and armv7s in the valid architecture setting, so does anyone know why am I getting those build errors on the armv7 device? I am missing something?
Here are the build settings for the libraries I'm using (openssl-xcode and sqlcipher):
To fix this read the comments above from Stephen and then I did a project clean and rebuilt it.

Resources