I'm trying to build a proxy framework around AudioKit so I can bind to it in Xamarin/C#. I've done this successfully with a few Objective-C libraries in the past (I did it with Superpowered, for example). This is my first attempt with swift. I'm seeking answers to a few basic questions.
I'm following the instructions for this here: https://docs.microsoft.com/en-us/xamarin/ios/platform/binding-swift/walkthrough which illustrates how to accomplish this with the Gigya framework.
I am using Xcode 12 and associated command line tools.
I got stuck trying to build the binaries. When I execute the following command:
xcodebuild -sdk iphoneos14.2 -project "AudioKitFrameworkProxy.xcodeproj" -configuration Release
I get the following build errors back to back:
xcodebuild error: module map file '/CAudioKitEX.modulemap' not found xcodebuild error: missing required module 'SwiftShims'
Note: this doesn't happen when I build the project from the Xcode UI. It builds successfully there.
Here are the steps I took to create AudioKitFrameworkProxy.xcodeproj:
- Created a "Swift Framework" called AudioKitFrameworkProxy.
- Added the AudioKit as a dependency: According to the MS example with Gigya, I am supposed to:
- Select the SwiftFrameworkProxy [in my case AudioKitFrameworkProxy] from the project files explorer then select the General tab
- Drag and drop the Gigya.framework package to the Xcode Frameworks and Libraries list under the General tab.
- Ensure that the Do Not Embed option is selected, which will be later controlled manually:
However, when I download the 5.2.1 version of AudioKit, there is no "Audiokit.framework" file.
Why is there no xxx.framework file for AudioKit? (again remember I know virtually nothing about developing swift frameworks so I'm assuming there was more than one way for AudioKit to package their framework.)
So, I added the 5.2.1 version of the AudioKit framework per AudioKit's instructions: File -> Swift Packages -> Add Package Dependency, entered the following URL: https://github.com/AudioKit/AudioKit and chose the 5.2.1 version.
AudioKit was successfully added to my project under "Swift Package Dependencies" which is a separate node in Project Navigator from my main "AudioKitFrameworkProxy" node. However, in the Gigya example the dependency is added in the project navigator under a "Frameworks" node directly under the SwiftFrameworkProxy project node. I don't understand the significance of this difference. However, it prevented me from following step 5 from above as there is not a drop down for me to select whether or not to embed the framework so I'm probably already off to a bad start.
- Ensure that the Build Settings option Always Embed Swift Standard Libraries, which includes Swift libraries with the framework is set to No. It will be later manually controlled, which Swift dylibs are included into the final package:
- Ensure that the Enable Bitcode option is set to No. As of right now Xamarin.iOS doesn't include Bitcode while Apple requires all libraries to support the same architectures:
- Ensure that the Objective-C Generated interface Header Name option is enabled and specifies a header name. The default name is -Swift.h:
- Expose desired methods and mark them with @objc attribute and apply additional rules defined below.
- Change the scheme build configuration from Debug to Release.
- Identify installed SDK versions in order to build the source code using xcodebuild tool
I was able to do these successfully. The next step is for me to build:
xcodebuild -sdk iphonesimulator14.2 -project AudioKitFrameworkProxy.xcodeproj -configuration Release
xcodebuild -sdk iphoneos14.2 -project "AudioKitFrameworkProxy.xcodeproj" -configuration Release
Both of which fail with the errors I quoted above.
Are the CAudioKitEX.modulemap and "SwiftShims" errors related to how I've added AudioKit? Why is Xcode expecting a .modulemap file when I use xcodebuild but not when I build in the Xcode UI? I'm guessing the Swiftshims error is related to the modulemap error as all the instructions I can find for eliminating the Swiftshims error (such as deleting all my DerivedData folder contents) didn't work.
Do I actually need an AudioKit.framework file to add and set to "Do not embed" per the MS instructions to get this to work properly?
Any tips or suggestions would be greatly appreciated!
Thanks,
Sean