Has anyone had any luck getting cocoapods imported...
# multiplatform
m
Has anyone had any luck getting cocoapods imported into a shared ios source source? Due to the way the presets work, there’s architecture specific versions (iosArm64 and iosX64). So i can create a source set for shared iOS code pretty easily. However, the problem is that I can’t manage to reference any cocoapods in it. Presumably because there’s additional work that has to go into configuring the preset which allows it to truly be an iOS specific module. I’d prefer to not have to repeat myself across the two ios architectures for all my code involving the pods i’m importing.
j
I'm doing this with an appleMain source set shared between iOS and macOS. I'm able to reference CocoaPods dependencies from appleMain. This is my source set dependency graph:
Copy code
______common______
                      |                  |
             _______apple______      jvmCommon
            |         |        |      |     |
        ___ios__  macosX64 macosArm64 |     |
       |    |   |                     |     |
iosArm64 iosX64 iosSimulatorArm64  android jvm
What IDE version are you using? How are you declaring your targets and source set dependencies?
m
@Jeff Lockhart
Copy code
val iosMain by creating {
            dependsOn(commonMain)
        }
        val iosTest by creating {
            dependsOn(commonTest)
        }

        val iosArm64Main by getting {
            dependsOn(iosMain)
        }
        val iosArm64Test by getting {
            dependsOn(iosTest)
        }

        val iosSimulatorArm64Main by getting {
            dependsOn(iosMain)
        }
        val iosSimulatorArm64Test by getting {
            dependsOn(iosTest)
        }

        val iosX64Main by getting {
            dependsOn(iosMain)
        }
        val iosX64Test by getting {
            dependsOn(iosTest)
        }
and i’m on 2022.2.1
j
Looks like you're not using the
ios()
shortcut, since you're creating iosMain and iosTest manually. That's one difference with my setup. But I just tried switching to manually creating as well and it continues to work the same. What is your CocoaPods dependency? Can you confirm you can see the dependency from code within iosArm64Main (or either of the other ios* source sets)?
m
yeah, i can see it in the other source sets. Let me try the ios() shortcut
as soon as i switch to using “ios { }” shortcut, it can no longer see any cocoapods in iosMain
Copy code
ios {
        binaries {
            framework {
                baseName = "AnalyticsMultiplatform"
            }
        }
    }
and here’s the cocoapods block
Copy code
cocoapods {
    summary = "AnalyticsMultiplatform"
    ios.deploymentTarget = "14.0"
    version = "1.0-SNAPSHOT"
    framework {
        baseName = "AnalyticsMultiplatform"
        isStatic = false
        transitiveExport = false
        embedBitcode(org.jetbrains.kotlin.gradle.plugin.mpp.BitcodeEmbeddingMode.DISABLE)
    }

    pod("DSJSONSchemaValidation")
}
j
as soon as i switch to using “ios { }” shortcut, it can no longer see any cocoapods in iosMain
I thought that it can't see the cocoapods in iosMain before using the
ios()
shortcut. Is this not the case?
I tried adding
pod("DSJSONSchemaValidation")
to my project and I am able to see those two imports in my shared apple source set.
What version of Kotlin are you using?
m
1.7.10
@Jeff Lockhart To answer your earlier question, the only place i’m ever able to resolve the cocoapods seems to be in iosX64Main or iosArm64Main
I changed to the iOS shortcut, and it is able to automatically see iosMain, iosX64Main and iosArm64Main as source directories without me having to deliberately add them with a “creating”. But no matter what i do, the iosMain never sees the cocoapods.
Finally found the solution. I needed this in gradle.properties (https://youtrack.jetbrains.com/issue/KT-41631/Commonization-of-CocoaPods-libraries)
Copy code
kotlin.mpp.enableCInteropCommonization=true
now, if i could only figure out how to build the xcframework properly
j
I needed this in gradle.properties
Copy code
kotlin.mpp.enableCInteropCommonization=true
Ah, yes. This makes sense. What are you running into with the xcframework build?