Garry
03/07/2024, 11:42 AMembedAndSignAppleFrameworkForXcode
Gradle task
• The compiler knows about the library via the FRAMEWORK_SEARCH_PATHS
and OTHER_LDFLAGS=-framework TheKmpLibrary
settings
• Our Xcode project uses custom configuration names (not the standard Debug and Release), so we set KOTLIN_FRAMEWORK_BUILD_TYPE
to map our configurations to build types accordingly
• Kotlin and KMP plugin version is 1.9.22.
Code completion doesn't work, nor can Xcode locate the header file when command-clicking on a symbol imported from the library - it just shows the dreaded Giant Question Mark icon and burps.
What's interesting is that both of these functions work if we build the library as an XCFramework, and import it using the standard Frameworks, libraries and embedded content mechanism in Xcode. This, however, is not a viable option in a monorepo where the KMP library is compiled from source alongside the Xcode project.
Any ideas? Are we missing something in our setup? Not having code completion is an absolute developer experience killer, especially with the name mapping from Kotlin to Swift.Garry
03/07/2024, 11:47 AMGarry
03/07/2024, 11:49 AMFRAMEWORK_SEARCH_PATHS=$(inherited) path/to/library/module/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)
Garry
03/07/2024, 7:43 PMGarry
03/07/2024, 7:51 PM/Users/<user>/Library/Developer/Xcode/DerivedData/<project>/Index.noindex/Build/Products/<Configuration>-<Platform>
.
When using an XCFramework linked in using the Xcode UI, the KMP shared library framework is copied to this folder. When using the embedAndSignAppleFrameworkForXcode
task approach, it is not.
What's also interesting is that that configuration
component of the indexer data folder path doesn't pick up the custom configuration name; even when building the project with a custom configuration, it seems to always be plain ol' debug or release.
Putting it together: this seems to make the difference for code completion; after manually copying the KMP library framework folder to the indexer data location, code completion and symbol recognition works again.Garry
03/07/2024, 7:53 PM./gradlew :shared:embedAndSignAppleFrameworkForXcode
DERIVED_DATA_DIR=$(echo "${TARGET_BUILD_DIR}" | awk -F'/Build/' '{print $1}')
INDEXER_DATA_DIR=${DERIVED_DATA_DIR}/Index.noindex/Build/Products/Debug-$PLATFORM_NAME
mkdir -p $INDEXER_DATA_DIR
cp -R shared/build/xcode-frameworks/$CONFIGURATION/$SDK_NAME/* ${INDEXER_DATA_DIR}
Maybe this'll help some other folks who were having issues with code completion.Rémi Thaunay
03/28/2025, 10:27 AMcp -R "shared/build/xcode-frameworks/$CONFIGURATION/$SDK_NAME/"* "${INDEXER_DATA_DIR}"