Carthage: Multiple build commands for output file framework - swift

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.

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

Gitlab phase contains a reference to a missing file when adding framework to Xcode project

I am struggling with a problem while using Gitlab CI/CD.
I am using for my project two of my external frameworks. The project builds without errors but when running the pipeline I'm getting an error that says
This Copy Files build phase contains a reference to a missing file 'xxxxxx.framework'.
My project looks like bellow
This is en error I'm getting:
When I add framework file not the framework project then CI/CD will pass BUT then I'm getting the error when trying to archive project
Building for iOS, but the linked framework 'xxxxxx.framework' was built for iOS Simulator.
I don't know how to solve those problems to get everything work.
Thanks for any kind of help.
Regards
In case anyone is having this problem and is cloning a git repository that has submodules, be sure include the submodules when cloning.
Most probably what you will need out of these 2 options is to use the x.framework one. The error
Building for iOS, but the linked framework 'xxxxxx.framework' was built for iOS Simulator.
as it says, comes from the fact that the framework is only built for iOS Simulator.
Why is that?
Well, the iOS Simulator runs on x86_64 architecture (as OS X does), while iOS runs on arm architecture. So you'll have to compile the frameworks for both architectures. Fortunately, there is a way to do this, and basically what you need to achieve is to create a fat binary of the framework.
There is a script here from Sundeep Gupta https://gist.github.com/sundeepgupta/3ad9c6106e2cd9f51c68cf9f475191fa which can be used to compile the frameworks for both, iOS Simulator and iOS target architectures. There are also several different resources on the internet which explain what steps you need to make in order to create fat binaries.

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!

Could not find module 'TLSphinx' for architecture 'arm64'; found: i386

I am using the TLSphinx from GitHub with my Xcode Swift iOS Project. I had built the TLSphinx project before I used the framework.
I had been given incomplete and confusing instructions from spinxbase on GitHub, pocketsphinx, and pocketspinx-ios-demo. It's not clear what those have to do with TLSphinx. I didn't alter TLSphinx in any way to use those other sources. I have filed issues with the appropriate repositories.
At the import statement for TLSphinx in my Swift file in my project, I get this error:
Could not find module 'TLSphinx' for architecture 'arm64'; found: i386
How do I fix this?
Depending how you are building "TLSphinx" framework, this error basically means that the framework was built for iOS simulator 32-bits, not for iPhone devices, which require arm64 architecture.
To remedy this, I suggest you use Carthage as the repo seems to support it. If you don't want to fully integrate Carthage with your project, the very least amount of steps you need to take are:
Create a temp directory somewhere, say mkdir foo && cd foo
Create Cartfile with the following line: github "Tryolabs/TLSphinx"
Run carthage update --platform iOS
Drag Carthage/Build/iOS/TLSphinx into your project
Update framework search paths in your project settings to where the framework is
Build, run.
Once you are prepared to ship to the AppStore, make sure to learn more about Carthage, and use copy-framework command to strip simulator slices.

Cross-compiling open-source c library for iOS and XCode 4.3

I'd like to use the excellent stringencoders library in an iOS application. It's a fairly typical c library, with a configure script generated by autoconf and a makefile.
What I'd like to do is compile arm7 and i386 versions on Mac OSX and then use lipo to make a fat binary.
I'm having trouble figuring out how to persuade the build tools to create my platform-specific binaries. There's a few articles out there and even a few scripts but most of them are targeted at XCode 4.2 and don't work with 4.3.
It looks like it should be possible to create a fairly generic build script that can play nicely with configure and make but I'm at a loss as to where to even start.
Have you successfully done anything like this? I'd love some pointers!
BTW: 'import all the sourcecode into your project' is NOT a viable solution. That way lies madness.
Thanks.
I've ported a handful of open source C libraries to iOS (see iOS Ports). I've found the most reliable way to port a library is to build a new Xcode project with a build target for a static iOS Library. It is important to note that Apple will not allow your iOS Application to contain dynamic libraries if you plan to distribute your app on the iTunes App store, so you will be unable to use FAT libraries.
These are the steps I usually follow when porting libraries to iOS which usually built with the GNU Autotools:
Run ./configure with appropriate flags on OS X.
Verify that the library builds correctly on OS X using make.
Create a new Xcode project using the iOS Static Library template.
Add the config.h from the previous configure run to the Xcode project.
Read the automake file (Makefile.am), and add the referenced sources in the automaker targets to the Xcode target for the static library.
Copy the CPP flags (i.e. -DHAVE_CONFIG_H) from the automake file to the build settings in Xcode.
Compile in Xcode and start running down errors (usually by adding missing header include paths or missing source files).
The directory structure I usually use is the following:
project/
project/ported-project.xcodeproj
project/project-x.x.x.tar.gz
project/project-x.x.x
project/project -> project-x.x.x
I know this is not exactly what you asked for in your question, however it is rough outline of the steps I've used for years for porting libraries. The benefit of creating an actual Xcode to compile the ported library is that it makes it easier to integrate the library into multiple Xcode iOS applications.
If you need clarification or more detailed instructions, let me know and I"ll try to write up more extensive instructions and update my answer.
Is it plausible to add the source files (i.e. .c files) to your project directly?
Objective C is a superset of C so i am surprised that the code did not work directly out of the box in XCode 4. Are you missing out something there ? just suggesting
Generate your project files using gyp: http://code.google.com/p/gyp/
I use it to share libraries between win/osx/ios and linux (pi).