In your Xcode project add a Run Script phase with the following commands:
cd "$SRCROOT/.."
./gradlew :common:buildForXcode
Tick the Use discovered dependency file
box and enter this as the path:
$(SRCROOT)/../common/build/bin/ios/$(CONFIGURATION)-$(PLATFORM_NAME)-deps.d
Add the following path to your project's Framework Search Paths (both Debug and Release) under Build Settings:
$(SRCROOT)/../common/build/bin/ios/$(CONFIGURATION)-$(PLATFORM_NAME)
Last step is to add the common code framework to Frameworks, Libraries and Embedded Content under your project's General settings. Build the common code once by manually running the buildForXcode Gradle task. Then locate the built .framework
folder under common/build/bin/ios/Debug-iphonesimulator/
and add it to this section in your Xcode project. Unfortunately there's no official way to tell Xcode to change this path depending on the values of the $CONFIGURATION
and $PLATFORM_NAME
build variables. We now have to modify the project's project.pbxproj
file manually in a text editor. Open this file and locate the Begin PBXFileReference section
section. There should be an entry in that section looking something like:
850863702548163B006C970C /* ... */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SpamdrainCommon.framework; path = "../common/build/bin/ios/Debug-iphonesimulator/MyFramework.framework"; sourceTree = "<group>"; };
Change this to
850863702548163B006C970C /* ... */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SpamdrainCommon.framework; path = "../common/build/bin/ios/$(CONFIGURATION)-$(PLATFORM_NAME)/MyFramework.framework"; sourceTree = "<group>"; };