Getting error while building iOS app from flutter - ios

I am trying to build iOS app from flutter and getting below errors.

Read https://github.com/flutter/flutter/issues/17749
Check Configuration here
In Short:
Flutter frameworks contain armv7, arm64, and x86_64 slices but NOT i386. When you run in the simulator, Xcode silently maps armv7 to i386 simulator and arm64 to the x86_64 simulator. ONLY_ACTIVE_ARCH=YES build setting builds only for the architecture of the device or simulator you are targeting. Xcode docs:
If enabled, only the active architecture is built. This setting will be ignored when building with a run destination which does not define a specific architecture, such as a 'Generic Device' run destination.
So if you are targeting a real recent iOS device, it will build arm64, and if you target a recent simulator, it will build x86_64. ONLY_ACTIVE_ARCH=YES is the default for the Debug build configuration for new Xcode projects.
If you have ONLY_ACTIVE_ARCH=NO and target a real device, it will build armv7 and arm64 and will succeed. If you target a simulator, it will try to build i386 and x86_64 and fail with this error because i386 is missing. ONLY_ACTIVE_ARCH=NO is the default for Release build configurations for new Xcode projects because you need to publish all valid architectures to the App Store.
Flutter is not supported in Release on the simulator.

Related

Xcode build target difference - arm64 and armv7, arm64

I had created 2 new projects on Xcode this week for 2 different apps. For some reason one of the project always fails compiling for the device target. I then realized that the device target is different for both the project. For the working project "Any iOS Project (arm64)" The project which fails to build has "Any iOS Project (armv7, arm64)"
What causes the device target to change this way and what is the difference?
armv7 is 32bit architecture that was supported by earlier iOS versions up till 10.3.4. arm64 is 64bit architecture which is supported by newer devices.
If your project has minimum iOS version which is below iOS 11.0, Xcode will automatically pick both armv7 and arm64.
In case if Xcode does not pick the required architecture automatically, it can be added in build settings as shown below:

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.

iPad: file was built for armv7 which is not the architecture being linked (arm64)

I have been developing my app using Simulator and an old iPhone 4S.
I tried to run the app on an iPad Mini 3, but I get this warning:
file was built for armv7 which is not the architecture being linked (arm64)
any idea on how to fix it?
EDIT:
The error was related to the UnitTest target.
I deleted such target (as I am not doing unit tests) and the warning disappeared.
For each target that needs to be built:
Go to Build Settings > Architectures
Set to $(ARCHS_STANDARD)
Go to Build Settings > Valid Architectures
Set to arm64, armv7, armv7s
Perform a Product > Clean just to be safe and Product > Build your project for the iPad Mini 3.

Xcode 6 iOS Simulator (iPad2, iPhone5) now Release Mode now running x86_64. Debug i386

Just noticed the Simulator for the devices that do not run arm64 (so iPhone4/5, iPad 2, which should be running i386 simulator) runs x86_64 in the simulator for release mode now in Xcode 6 by default.
To clarify: Debug mode still calls i386 for these simulator targets... so weird.
Noted in the build log:
clang++ -arch x86_64
This is a bit of an issue testing for older projects that only compiled vs the old i386/i686 architecture for release mode.
Anyone have any idea how to make it run in i386 for release as well?
Solution!!!
Set Build Active Architecture Only to Yes

Error when trying to link fat binary with 64-bit simulator target

I have a static library lipo'd for iOS and OS X with 5 architectures (x86_64, i386, armv7, armv7s, arm64).
The x86_64 architecture was built using the macosx SDK
The i386 architecture was built using the iphonesimulator SDK
The ARM architectures were built using the iphoneos SDK
When I try to link the resulting library in an example App it works when building for a device or for a 32-bit iOS simulator target. But when I try to build it for a 64-bit iOS simulator target I get a linker error:
ld: framework not found CoreServices for architecture x86_64
If I remove the x86_64 slice from the fat library it works for all devices and simulators.
I assume it's because the linker prefers the x86_64 architecture if it's there for the 64-bit simulator. But since it was compiled and linked for the macosx SDK it has the OS X dependencies somehow encoded.
I tried adding a second x68_64 slice for the iphonesimulator SDK but lipo won't let me. Also I tried to find a way to make the simulator use the i386 architecture even for 64-bit builds, but so far no luck.
If absolutely necessary I can create 2 binaries which would solve this but I would really prefer having them in one file. Is there a way to achieve this?
I solved it by only building it for the iOS device and simulator. The 64bit slice of the iOS Simulator SDK equally works for iOS and OS X targets, provided you don't need any other frameworks than what's shared between OS X and iOS (Foundation only in my case).
Project and Pods:
Build Settings ---> Link Frameworks Automatically change YES to NO, and rebuild static library ,it is work!

Resources