mach-o, but wrong architecture AFNetworking 3.0 - ios

Anybody know about the error “mach-o, but wrong architecture” ? I have built a custom framework(which includes a few other SDK's inside it) & trying to integrate in the client project. I can use/access the custom framework’s methods in the client’s app when I am running in a simulator, but the app is getting crashed while running on the device . Any suggestions will be really helpful. Thanks
Here is the log:-
dyld: Library not loaded: #rpath/AFNetworking.framework/AFNetworking
Referenced from:
/private/var/containers/Bundle/Application/644C95E8-6CFD-48BB-861E-7BCECB08FE43/abc_client.app/Frameworks/XYZ_iOS.framework/XYZ_iOS
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/644C95E8-6CFD-48BB-861E-7BCECB08FE43/abc_client.app/Frameworks/XYZ_iOS.framework/Frameworks/AFNetworking.framework/AFNetworking:
mach-o, but wrong architecture
/private/var/containers/Bundle/Application/644C95E8-6CFD-48BB-861E-7BCECB08FE43/abc_client.app/Frameworks/XYZ_iOS.framework/Frameworks/AFNetworking.framework/AFNetworking:
mach-o, but wrong architecture

When building for the Cocoa platform, Elements allows you to choose to build for different CPU Architectures, depending on the target devices and operating system versions you wish to support. Elements allows the creation of so-called "Universal Binaries", or "Fat Binaries", that can include executable code for more than one platform (for example 32-bit and 64-bit). source
The error means that there are architectures which are missing in your framework.
List an architectures in a framework:
There are two terminal tools:
file
file /path/to/MyFramework.framework/MyFramework source
Example output:
path/to//MyFramework.framework/MyFramework: Mach-O universal binary with 5 architectures
path/to//MyFramework.framework/MyFramework (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
path/to//MyFramework.framework/MyFramework (for architecture i386): Mach-O dynamically linked shared library i386
path/to//MyFramework.framework/MyFramework (for architecture armv7): Mach-O dynamically linked shared library arm
path/to//MyFramework.framework/MyFramework (for architecture armv7s): Mach-O dynamically linked shared library arm
path/to//MyFramework.framework/MyFramework (for architecture arm64): Mach-O 64-bit dynamically linked shared library
lipo
lipo -info /usr/lib/libiodbc.a source
When launching on a device a framework have to include arm64 or
armv7 architecture
When launching on a simulator a framework must
to include x86_64 architecture
Solution
Check if there is any modifications to architectures in Podfile
Check if there is any modifications to the project build settings for a architectures keys.

Related

Optional library with missing simulator architecture

I have a 3rd party static library that hasn't been updated in a long time. As such, it does not include an iPhone simulator build for M1 Macs.
% lipo -info ./Zebra/lib/libZSDK_API.a
Architectures in the fat file: ./Zebra/lib/libZSDK_API.a are: armv7 i386 x86_64 arm64
I tried to set the "Link Binary With Libraries" to be optional for this library so I can still run on the Simulator. (The library is just for printing, and I don't need to print from the Simulator.)
The problem is that even though I have marked the static library as optional, Xcode still gives me a linker error about the missing architecture.
error build: In ../XXXX/External/Zebra/lib/libZSDK_API.a(TcpPrinterConnection.o), building for iOS Simulator, but linking in object file built for iOS, file '../XXXX/External/Zebra/lib/libZSDK_API.a' for architecture arm64
Is there any way to get around this so that Xcode does not fail the build, but just leaves the library unlinked? I thought this was the whole point of the "optional" setting on Link Binary With Libraries?

importing swift framework only working on Simulator

I have been trying to import this swift framework into a objective c project called CreditCardForm but it fails to run. It will run on a real iPhone but when it comes to the simulator it gives be this error.
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$__TtC14CreditCardForm18CreditCardFormView", referenced
from:
objc-class-ref in CreditCardVC.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code
1 (use -v to see invocation)
I have been trying to get it to run but it has only ran for the simulator only or the iPhone only.
Make sure the framework is built in both Device/Simulator
If the project is built only in “Simulator”, it would only generate architectures which would let the framework run specifically on simulators not on Devices. Or if the project is built in “Device”, it would generate architectures which would let the framework to run only on devices.
So build the project on both “Simulator” and “Device”.
https://medium.com/swiftindia/build-a-custom-universal-framework-on-ios-swift-549c084de7c8
Build a Fat Library
A fat library is simply a library with multiple architectures. In our
case it will contain x86 and arm architectures. The proper name is
‘Universal Static Library’. But we will stick with ‘fat library’ since
its smaller to write and that is exactly what our resultant library
would be. Fat!!! with multiple architectures in it.
https://medium.com/#hassanahmedkhan/a-noobs-guide-to-creating-a-fat-library-for-ios-bafe8452b84b

IOS native plugin for universal architecture

I have a project in Unity3d that uses an iOS native plugin that I made in Xcode.
I use Unity3d v4.6.2 with Scripting Backend option in IL2CPP and Architecture option in "Universal"
Whem I run the project on my ipod5, it works but when I want to archive it, I have errors links with my library:
Undefined symbols for architecture arm64
with a warning that says
file was built for archive which is not the architecture being linked (arm64)
My library configuration is the following
http://imgur.com/AvbBYFo
and my list of iOS simulators is
http://imgur.com/XlSojzT
I try them all and none works
When I run the command
lipo -info mylib.a
I see the following information
input file mylib.a is not a fat file
Non-fat file: mylib.a is architecture: x86_64
I need my project to all the architecture, but do not know what else to configure.
Thanks for your help

file was built for arm64 which is not the architecture being linked (x86_64)

I am building a framework first to use in my ios simulator. However I get this error when importing it into the main project:
file was built for arm64 which is not the architecture being linked
(x86_64)
Here is the build info of my framework:
UPDATE:
I created a universal framework using this technique: https://medium.com/#syshen/create-an-ios-universal-framework-148eb130a46c but I'm still getting the error
UPDATE: Results from running file on the binary:
hunterp$ file dinkle
dinkle: Mach-O universal binary with 2 architectures
dinkle (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
dinkle (for architecture arm64): Mach-O 64-bit dynamically linked shared library
I was incorrectly copying the binary framework and using an old one from before I changed it into a universal.
To create framework and convert .h file into .a fat file. Compile your project with simulator target and device target ,after these two tasks you have to join to make universal file with shell.

Dynamic library image doesn't contain x86_64, i386 architectures

I'm trying to build dynamic library for iOS, combined with architectures
armv7
armv7s
arm64
i386
x86_64
Here is my target's Build Settings
As you can see I've added x86_64 and i386 to Architectures and Valid Architectures, also Build Active Architecture Only is set to NO.
So after building my binary, I'm checking supported architectures by running file myDl.dylib in Terminal
myDl.dylib (for architecture armv7): Mach-O dynamically linked shared library arm
myDl.dylib (for architecture arm64): Mach-O 64-bit dynamically linked shared library
So it means it has been compiled for armv7 and arm64, and dlopen() fails on simulator with error "Unsupported architecture".
What am I doing wrong?
PS. When I use custom build script and use there "lipo" tool to create fat library, it works fine, but I don't like that way, and I want to get it normal working on Xcode.
Set armv7,armv7s and arm64 in valid architecture and make sure if you use any thirdparty framework that must be include 64 bit support.

Resources