Building project for M1 Mac fails because of architectures it believes are missing - swift

We have a project that uses many AWS libraries. On first attempting to build it, using carthage, it downloaded binaries and it did not build at all. So we ran carthage --no-use-binaries and it built the libs.
Then this error occurs:
LoginService.swift:9:8: Module 'AWSMobileClient' was created for incompatible target arm64-apple-ios9.0: ..Carthage/Build/iOS/AWSMobileClient.framework/Modules/AWSMobileClient.swiftmodule/arm64.swiftmodule
Based on this stack overflow thread, we add arm64 to excluded architectures for the simulator.
Which makes all the aws code compile (yay) but then, this error occurs trying to use a framework that is coming in via the Swift Package Manager:
[].swift:10:8: Could not find module 'Parma' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios-simulator
So it wants the x86 version of this lib, and cannot find it.
The app does run on the phone now. But not the simulator of course. Not sure if there is a way to figure out which architectures are built by SPM? or control it. I did reset the SPM cache after excluding the arm64 arch.

I think the best solution for getting this working on M1 is to use XC-Frameworks.
carthage update --use-xcframeworks
This will only build the valid archs you need. If you have any dependencies that don't support XCFrameworks yet you'll have to run lipo to remove x86 simulator targets in your build phase.

Hey I've come across the issue. Just open your old project by Rosetta and build it. Then uncheck open by Rosetta and build it. It helped me to open old project on m1

Related

Need to re-install libraries before every build (Carthage)

My team and I are working on a Swift project (Swift 5 - XCode 11), and decided to use Carthage as our dependency manager to handle libraries such as SwiftyJSON, SDWebImage and MapBox. We have done the setup as specified on Carthage's GitHub: created a Cartfile, downloaded the libraries, dragged the files onto the "Frameworks, Libraries & Embedded content" part of XCode, added a Build stage as Carthage requests it...
My problem is: after almost every successful build, when I try to run the application, the build fails because one of the packages is not recognised: the message says: "Swift compiler error. No such module 'SwiftyJSON'" (or any of the other libraries).
To sort out this problem temporarily, I re-download again all packages by running:
$ carthage update --platform ios
The problem is that I need to re-do this update every time I build my application, otherwise it fails. None of my other three teammates are facing this issue.
Would be really helpful if someone knew the source of this problem, I have tried almost everything!
Thank you!

Carthage: Multiple build commands for output file framework

I'm using Carthage for dependency management and have a bunch of warnings in my project:
"Multiple build commands for output file /Users/me/Library/Developer/Xcode/DerivedData/project-ymeymeyme/Build/Products/Debug-iphonesimulator/project.app/Frameworks/Alamofire.framework"
I'm not sure if the best way to take care of this is to just delete from derived data folder, or to remove in Build Phases from Link Binary With Libraries or Embed Frameworks or something?
Any idea? Thanks!
Seems to me that you are bundling the mentioned framework twice. (https://stackoverflow.com/a/5659415/1120481)
You mentioned that your target has a Run Script build phase with /usr/local/bin/carthage copy-frameworks what is recommended in the Carthage README file for iOS, tvOS and watchOS.
You're also asking whether you should remove the framework from Embedded Binaries. Did you add the framework to this list? If yes you may have mixed up the Carthage setup instructions for macOS and iOS, tvOS, watchOS.
If you're building for macOS, remove the script phase.
If you're building for iOS, tvOS or watchOS, remove the framework from Embedded Binaries.
I fixed the issue by changing the order of the Run Script phase that executes /usr/local/bin/carthage copy-frameworks below Embed Frameworks. This happens to be the last build phase for this target.

Xcode 8 Builds Successfully but Fails on Archive

I am writing a program in Swift using Mac OS Sierra and Xcode 8.3.2 and am using the RandomKit module from: https://github.com/nvzqz/RandomKit. I am using the basic Swift Package Manager to import the package into my project.
My program builds and runs fine, but when I go to archive it, I get an error saying "No such module 'RandomKit'
It highlights my code:
import RandomKit
Does anyone know why this would build and run but fail when I attempt to archive?
By default, when you Run in XCode, it uses the Debug configuration, and when you Archive, it uses the Release configuration. In Build Settings, look at the Build Active Architecture Only setting. By default, it is Yes for Debug, and No for Release.
This means that when you Run, XCode only builds for the simulator's architecture, but when you Archive, it builds for all possible iOS architectures.
Now, look at the settings for RandomKit to see what architectures it is built for. It needs to include all of the iOS architectures, like arm64, armv7, and armv7s.
After probably 4 hours I finally figured it out. I think this must be a bug in Xcode, but here is my workaround.
In this folder:
~/Library/Developer/Xcode/DerivedData/<My App Name>/Build/Products/Debug
I found RandomKit.framework and ShiftOperations.framework. I copied those two files into the root directory of my Xcode Project, and then linked the frameworks under General in my Xcode Project.
Linking Frameworks

Cocos2d-x project's 2nd rebuild onwards gives an error 'Xcode cannor run using selected device'

Fresh cocos2d-x project build using Xcode runs normally on iOS simulator/device, but after making changes to cpp source files, rebuild fails with error-
Xcode cannor run using selected device. Choose a destination with a supported architecture in order to run on this device.
The only way to make it work is delete build binaries (i.e. delete XCode>Derived Data folder), and take fresh build after restarting Xcode.
Can someone please help me resolve this issue?
Additional Details:
This error is related to mismatching device architecture and armv6 armv7 flags. But first build works fine, and stops working after second build onwards, that means this is not a possible issue.
If the project is not using cocos2d-x (i.e. plain Objective-C project), then there is no such error after second build.
Compiler selected: Apple LLVM Compiler 4.2
Thanks in advance!
Following my comment you should make sure you use the latest templates for creating cocos2d projects. Some templates will only work for a specific Xcode version so make sure you use the right templates for your xcode version (There are some for xcode 3.x and others for xcode 4.x)
Change Valid architecture to armv7 and armv7s. Remove armv6. See image for more information.

Cannot compile a static library for arch armv7

I have a static library (very simple, no includes) which builds fine with "-arch i386", I can use the demo method in this library and everything is fine. As usual I have an .a file to link in my project.
Unfortunately I want to use this library in an iOS project, so when I use the iPhone Simulator everything is fine with the library built with "-arch i386" (because this is the processor the simulator uses). If I now want to build the library with "-arch armv7" (or "-arch armv6") for my ARM-based iPhone device I get in Eclipse and in Xcode the same error message: (in Xcode:) llvm-gcc-4.2 failed with exit code 255. Same exit code in Eclipse (255). With "i386" everything works.
Must I install anything in addition to my Xcode 4.2.1 on OSX Lion to make compile the lib for my ARM-Device?
The issue lies in the fact that Xcode 4 builds static libraries for each build rather than one unified universal build. So my guess is that you are just adding the build for debug-simulator and not for debug-device. Your best bet, add a script to your static library to build them all into one.
This post here on SO saved my life. Hopefully it will help you too.