1 year ago
    hi all, happy monday! I'm attempting to use cocoapod dependencies in the shared module of a kotlin multiplatform mobile project and failing miserably. Full details in thread:
    I've been following, which points to I'm using the current stable build of Android Studio (4.1). I've installed cocoapods 1.9.3 using
    sudo gem install cocoapods -v 1.9.3
    (there seems to be an issue with
    and cocoapods 1.10.0). I've created a brand new project using the KMM project template. Next I've added
    to the plugins block in my build.gradle.kts file in the shared module. gotcha #1: The guide includes a version for the plugin, but in practice this causes a build error
    Plugin request for plugin already on the classpath must not include a version
    . I'm assuming the inclusion of the
    in the classpath in the project's build.gradle.kts is somehow declaring the version of the native.cocoapods plugin as well. At this point the next step is to use the cocoapods extension in the kotlin block in the shared module's build.gradle.kts. So I've added:
    cocoapods {
        summary = "Some description for a Kotlin/Native module"
        homepage = "Link to a Kotlin/Native module homepage"
    These values will be used in the generated podspec file. gotcha #2: A this point the project will fail to build again with the error:
    Cannot create binary debugFramework: binary with such a name already exists
    pointing to the line where we try to configure the output framework within the ios block. Presumably the cocoapods plugin is trying to do this, so we shouldn't do it twice. Here I'm replacing:
    ios {
        binaries {
            framework {
                baseName = "shared"
    At this point the guide says to "Re-import the project". I don't actually know what they mean by this. There does seem to be a process where you can close the AS project, delete the .idea folder and then import the project into AS again, but this doesn't seem to help. So far the iOS app will build and run, but we haven't added or used any external cocoapod dependencies. So to test this out I added
    pod("AFNetworking", "~> 4.0.0")
    to the cocoapods block. gotcha #3: Here, the build error is actually pretty clear
    Specs satisfying the AFNetworking (~> 4.0.0) dependency were found, but they required a higher minimum deployment target.
    and it suggests adding
    ios.deploymentTarget = "..."
    . So if we add
    ios.deploymentTarget = "9.0"
    (the minimum version required by AFNetworking 4.0.0, it will build) But this is where I hit a brick wall. The guide says you can now use external cocoapod dependencies with an import statement like
    import cocoapods.AFNetworking.*
    , but if I include this in Platform.kt in the iosMain directory, the IDE doesn't recognize it, giving the error
    Unresolved reference: AFNetworking
    . And I try to use it as the sample project does ( by including:
    init {
    That too is an unresolved reference, and trying to run the app from the IDE fails with:
    Undefined symbols for architecture x86_64:
      "_AFNetworkingReachabilityNotificationStatusItem", referenced from:
          _cocoapods_AFNetworking_AFNetworkingReachabilityNotificationStatusItem_getter_wrapper12 in shared(result.o)
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    so what am i missing here