ioscocoapodskotlin-multiplatform

iosMain shows `Unresolved reference: cocoapods`


I am successfully building my app with cocoapods, but when I try to import my dependencies in iosMain, I get ERROR: Unresolved reference: cocoapods.

I've honed my gradle file to match just about every working KMP library I could find on GitHub, and I've incorporated much of the good advice here as well. Here's my build.gradle.kts file:

plugins {
    alias(libs.plugins.androidLibrary)
    kotlin("multiplatform") version "2.0.20"
    kotlin("native.cocoapods") version "2.0.20"
}

kotlin {
    iosX64()
    iosArm64()
    iosSimulatorArm64()

    cocoapods {
        ios.deploymentTarget = libs.versions.ios.deploymentTarget.get()
        framework {
            baseName = "TestGoogleMobileAds" // named differently to prevent error
            isStatic = true
        }
        noPodspec()
        pod("Google-Mobile-Ads-SDK") {
            version = libs.versions.adMob.cocoapods.get()
            extraOpts += listOf("-compiler-option", "-fmodules")
        }
    }

Here's my current system information:

Android Studio: Koala Feature Drop | 2024.1.2 Patch 1
Xcode: Version 16.0
cocoapods: 1.15.2

My goal is to be able to incorporate the Google-Mobile-Ads-SDK library in iosMain like so:

import cocoapods.GoogleMobileAds.*

How do I modify my build.gradle.kts file or some other file in my KMP project to achieve this?

EDIT: The issue may be related to this ticket, which is being resolved in Kotlin 2.0.21.


Solution

  • The error was the result of upgrading Xcode to v16.*.

    I fixed the issue by increasing Kotlin version to 2.1.0-Beta1, per this post.