I'm working on a KMP multimodule project for iOS and Android and I have an issue with cocoapods dependencies in submodules.
I have an umbrella shared module that has other modules as dependencies.
shared (umbrella module)
|
| build.gradle.kts
cocoapods {
// standard cocoapods block with dynamic linking
...
}
sourceSets {
commonMain.dependencies {
//put your multiplatform dependencies here
implementation(project("sharedcore"))
}
commonTest.dependencies {
implementation(libs.kotlin.test) // dependency towards the core module
}
}
- core module
build.gradle.kts
cocoapods {
... default cocoapods block with dynamic linking
}
sourceSets {
commonMain.dependencies {
//put your multiplatform dependencies here
implementation(project("sharedlogger")) // dependency towards the logger module
}
commonTest.dependencies {
implementation(libs.kotlin.test)
}
}
- logger module
build.gradle.kts
cocoapods {
... // standard cocoapods block with dynamic linking
pod("FirebaseCrashlytics") { // defines a dependency towards FirebaseCrashlytics pod
extraOpts += listOf("-compiler-option", "-fmodules")
}
}
The error I have with this is
Execution failed for task 'sharedlinkDebugTestIosSimulatorArm64'. ld: framework 'FirebaseCrashlytics' not found
However, the FirebaseCrashlytics pod appears in shared/build/cocoapods/synthetics.
Now if I add the FirebaseCrashlytics pod into the umbrella module cocoapods block too I get:
e: Compilation failed: Linking globals named 'knifunptr_cocoapods_FirebaseCrashlytics1_FirebaseCrashlyticsVersionNumber_getter': symbol multiply defined!
Has anyone experience with this setup? Any idea on how to make it work?
f
François
08/08/2024, 6:09 AM
How about the xcode integration? the Podfile is declared only once? are you using a static or dynamic cocoapods integration?
François
08/08/2024, 6:13 AM
the way you’re using cocoapods could be unsupported or buggy, the cocoapods integration is kind of weird in borderline case.
g
Gradinariu Tiberiu
08/08/2024, 10:55 AM
well, this is my Podfile
target 'iosApp' do
use_frameworks!
platform :ios, '16.0'
pod 'shared', :path => '../shared'
end
I've managed to make it work with some inspiration from an older SO post: https://stackoverflow.com/questions/70456588/nested-multiplatform-libraries-usage-with-cocoapods-intergration
The fix is to link the submodule dependencies using api(project("submodule")) instead of implementation(project("submodule")) AND to declare the pod in each module that depends on the source submodule.