Xcode 8 Builds Successfully but Fails on Archive - swift

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

Related

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

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

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.

XCode 4.4.1: Can't Deploy to Device or Simulator: Unsupported architecture

I'm having some trouble deploying to any device in XCode 4.4. I have only tested on armv7 devices, but I only wish to deploy to armv7. The application compiles without issue.
Device Error
Simulator Error
I have checked that the Architectures and the Valid Architectures in the build settings contain only armv7.
I'm working in an XCode Workspace with one project and one subproject. The subproject creates a static library which acts as a target dependancy to the main project.
Other questions suggest that the deployment target might be wrong, but I checked this too and it is set to iOS4.0 for all projects and targets. (All devices are iOS5.0 +)
Does anyone have any suggestions please?
Though I couldn't find exactly why this was happening. I fixed it by removing the project data.
Close XCode
Open Terminal
cd to your .xcodeproj directory
Recursively delete any project data files associated with the current user name
find . -name "YOUR_OSX_USERNAME_HERE*" | xargs rm -rf
Reopen XCode
Just for luck, do a clean build
Edit
Had this error again and wasn't solved by the above steps alone. There were two other factors:
Make sure Info.plist isn't part of the Target Membership
Clear DerivedData
Quit Xcode and iPhone simulator
Unplug your devices
Goto ~/Library/Developer/Xcode/DerivedData/
Delete all data under this folder
Start Xcode again and run your project
I've found that Xcode really seems to like '$(ARCHS_STANDARD_32_BIT)' for 'Architectures'. If its not set to that try it, 'Valid Architectures' with armv7.
Just curious - if building for newer phones only, why not use a deployment target of 4.3? You'll be able to use some of the new block technologies not in the earlier releases.

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.

How to make Xcode 3.2.3 build a specfic architecture?

I'm getting the following error when including static libraries:
missing required architecture i386 in
file
This worked 30 seconds previously, and only failed when I upgraded to Xcode 3.2.3. I've used "file" command to check - and, yes, XCode is building completely the wrong architecture (armv6 + armv7 instead of i386).
This seems to be a major bug in latest Xcode, where Apple has re-written the build / compile / link settings. There's a note in the release notes saying very vaguely that they've "Changed it" because it used to be "confusing". This is not helpful.
The build settings for the library VERY clearly say:
"Valid architectures: i386"
There's no confusion here - Xcode is building something other than what the target says it should.
The question is: how do you un-break this? How do you force Xcode to do what it's supposed to? I've re-installed Xcode from scratch, cleaned everything, and manually inspected the build files. There's nothing wrong (and, of course, it worked perfectly in xcode 3.2.2)
After considerable research, I believe the answer is:
"this is now impossible - Apple has deliberately hard-coded XCode to ignore build settings"
However, I've come up with a script that automatically builds ALL platforms of a project (which you HAVE to do with static libraries - you don't have much choice now, because Apple has disabled Targets), and the script could easily be modified to do all targets, instead of all platforms:
Build fat static library (device + simulator) using Xcode and SDK 4+
Right click on your Target app under Targets and make sure that the Base SDK is set to iOS.