Module 'Swift' was created for incompatible target x86_64-apple-ios13.0 - ios

I'm creating an iOS framework and I want to copy some Xcode templates from my framework directory (that are not included in my .xcproject, but are in the folder that contains the project), when my framework is installed trought Cocoapods. In other words, when a developer installs my framework with Cocoapods or manually, I want to copy the templates into his Xcode Template Files folder.
I'm trying to execute a swift script file from the build phase of Xcode like this:
swift "${SRCROOT}/Folder/Folder/installer.swift"
But I get this error when I try to build it:
/<unknown>:1:1: module 'Swift' was created for incompatible target x86_64-apple-ios13.0: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64.swiftmodule
If I execute swift installer.swift from the terminal, the script works. So, I think there is a problem with my Xcode.
My installer.swift file copies the template files to the Xcode Template Files folder.
I don't know if this way is the correct one, but I didn't find any other solution so far.

When I tried something similar I had to tell swift to compile for macOS by adding the following "shebang" comment as the first line of the swift script:
#!/usr/bin/env xcrun --sdk macosx swift

Related

Xcode11 Archive fails: no such file or directory Objects-normal/arm64/UniversalSDK.SwiftFileList

I am trying to build a universal framework from existing source code in Xcode11.
When I Archive, it fails with following error:
/<unknown>:1:1: no such file or directory: '/Users/apple/SANDBOX/VoiceSampler/#/Users/apple/Library/Developer/Xcode/DerivedData/VoiceSampler-foeghskagbaeclezzbypkqnjnuos/Build/Intermediates.noindex/ArchiveIntermediates/BuildUniversalSDK/IntermediateBuildFilesPath/VoiceSampler.build/Release-iphoneos/UniversalSDK.build/Objects-normal/arm64/UniversalSDK.SwiftFileList'
/:1:1: no such file or directory: '/Users/apple/SANDBOX/VoiceSampler/#/Users/apple/Library/Developer/Xcode/DerivedData/VoiceSampler-foeghskagbaeclezzbypkqnjnuos/Build/Intermediates.noindex/ArchiveIntermediates/BuildUniversalSDK/IntermediateBuildFilesPath/VoiceSampler.build/Release-iphoneos/UniversalSDK.build/Objects-normal/arm64/UniversalSDK.SwiftFileList'
I was able to Archive the same in Xcode 10.3 earlier. Not sure what changed.
Please help me solve this Archive error.
I don't know if it helps, but for me it happens when I run the Swift compiler manually from inside XCode (a script which builds a separate Swift framework). XCode sets the environment variable SWIFT_RESPONSE_FILE_PATH_normal_x86_64 (variant and architecture) which points to that particular missing .SwiftFileList file. Unsetting this environmant variable solved the issue for us.
This is how we unset it in the external script:
for V in ${BUILD_VARIANTS}; do
for A in ${ARCHS}; do
unset SWIFT_RESPONSE_FILE_PATH_${V}_${A}
done
done
For me the issue was related with using the legacy build system instead of the new one (in Xcode 11). Once I switched to the New Build System (in File -> Workspace/Project Settings), these new lines started to appear in the build log:
WriteAuxiliaryFile /Users/.../XXXXXX.SwiftFileList (in target 'XXXX' from project 'XXX')

Using a static iOS library in a NativeScript 5.4 plugin

NativeScript 5.4.2
tns-core-modules 5.4.3
tns-ios 5.4.2
Xcode 10.2.1
I am attempting to create a plugin for this background geolocation library for iOS: https://github.com/Yermo/background-geolocation-ios
The project produces a static library, libBackgroundGeolocation.a.
I have read the documentation on how to use a static iOS library: https://docs.nativescript.org/plugins/Use-Native-iOS-Libraries#static-libraries
I have read about the required directory structure: https://docs.nativescript.org/plugins/plugin-reference#directory-structure
My plugin is based on the official plugin seed, so I have a demo directory and a src directory containing my plugin code and a platforms/ios directory under that.
I have copied the BackgroundGeolocation.a file into src/platforms/ios.
I have created a src/platforms/ios/include/BackgroundGeolocation directory and copied the public header files from the project into that directory.
I notice that src/platforms/ios/include/BackgroundGeolocation/module.modulemap file has been created.
In the plugin directory I can successfully run 'npm run build'.
However, from the demo directory if I run 'tns build ios' I consistently get a "ld: Library not found for -lBackgroundGeolocation" error.
If I rename the library to libBackgroundGeolocation.a I get the "ENOENT: no such file or directory, scandir '.....ios/include/libBackgroundGeolocation" so I surmise it's at least recognizing that the library is there.
I thought that maybe it was a path problem so I tried setting the library include path explicitly in build.xcconfig using the full path to the platforms/ios directory.
No joy. It still doesn't find the library but if I misspell the name of the directory in the -L in build.xcconfig it flags a directory not found error.
I then thought that maybe it had to do with the targets in the library so I followed the recipe here Build fat static library (device + simulator) using Xcode and SDK 4+ to include multiple targets.
Still no joy.
I suspect I am missing something fundamental.
What am I doing wrong?
Is there a working recent working sample somewhere of how to wrap a static iOS library as a NativeScript plugin?
It turns out adding
LIBRARY_SEARCH_PATHS = $(inherited) "$(SRCROOT)/../../node_modules/<projectname>/platforms/ios
to the src/platforms/ios/build.xcconfig file resolved this issue.

How to add a library or framework to XCode project at the runtime?

I want to add a static library mylib.a to Xcode at the runtime via buildscript. It needs to copy to project directory if needed as well.
I'll need something like following line of command to add just before the xcodebuild command in the buildscript. If anyone have done this before please share some example.
frameworkGroup = project.get_or_create_group('Frameworks')
project.add_file(/Users/###/Desktop/mylib.a,
parent=frameworkGroup,
tree='SDKROOT',
weak=false)

No such module "PackageDescription"

I just started with swift 3 and made a simple app in xcode using Swift 3.0 . Now i want to add a third party library using Swift Package Manager . I am following installation method given in this link . I created Package.swift file which looks like this
import PackageDescription
let package = Package (
name : "SwiftPM",
dependencies : [
.Package(url: "https://github.com/ArtSabintsev/Siren.git", majorVersion: 1)
])
but i get error No such module "PackageDescription"
The Swift Package Manager and Xcode are orthogonal. That is, you can't expect to compile Package.swift in Xcode; it simply won't work. Instead, until Xcode supports the package manager, you need to have two distinct builds - one with the package manager and one with Xcode.
So, using the Swift Package Manager, once you've defined Package.swift and formulated your directory structure as expected by the package manger, you perform simply:
swift build
Then for Xcode, you create an Xcode project that uses your source code, but not Package.swift. You'll need to clone the Siren.git project, explicitly - into your Xcode build's source files.
Swift 3/4
Navigate to your project folder through a terminal and run these commands swift package init --type library first and then swift package generate-xcodeproj
Reference
For me the issue turned out to be Target Membership. I created the Package.swift file manually inside an iOS app project.
Solution:
Select and go to the Package.swift file
Open the File Inspector on the right side
Deselect any modules inside Target Membership section
Refer to the solution in this link:
https://forums.kodeco.com/t/server-error-no-such-module-packagedescription/177438
Command:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
For other people who faced the same error as this:
Fix your Package.swift syntax
I got this error because Xcode hadn't parsed Package.swift fully yet, because of syntax errors.
In my case, I had a .target(name: "name-of-target", dependencies: [""]). As soon as I removed the empty dependency string (""), Xcode immediately parsed the file, and the error disappeared. Remember to save the file though.
Also, GoZoner and Pratiks answers are outdated:
Xcode has integration with Swift Packages now (as shown above)
swift package generate-xcodeproj is deprecated, shown by the error message when using it:
warning: Xcode can open and build Swift Packages directly. 'generate-xcodeproj' is no longer needed and will be deprecated soon.
More information about what that is, and why its gone here.

How to integrate .proto files in Xcode compilation?

I am trying to port an android app to ios and new to mac/xcode ecosystem. My app uses Google proto buffs and using instructions at https://github.com/alexeyxo/protobuf-swift/blob/master/README.md I am able to build protobuf for swift and add ProtocolBuffers.xcodeproj to my project. I was even able to generate .swift files for my proto files outside of xcode using protoc directly. However, my question is how do I integrate .proto files in Xcode so xcode can find/compile them? Do I need to copy my .proto files manually in my project? I am using Xcode 7.2.1 and protoc version is 3.0.0. Thanks in advance.
Create a build rule for *.proto files, something like this:
Add your .proto file to "Compile Sources" build phase list.

Resources