Following the 1.4-M2 blog post to change some of m...
# multiplatform
k
Following the 1.4-M2 blog post to change some of my gradle setup for a multiplatform mobile project and I keep getting the error "KotlinTarget with name 'ios' not found." Any help to get this working would be appreciated! 1. Upgraded Kotlin IntelliJ plugin to the latest one from 1.4-M2 2. Create new Kotlin project using the experimental wizard, chose to use kts for the gradle files 3. Everything builds fine after this step 4. Added
kotlin.mpp.enableGranularSourceSetsMetadata=true
to gradle.properties file 5. Changed shared build.gradle.kts to have
Copy code
kotlin {
    android()
    ios()
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(kotlin("stdlib-common"))
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation(kotlin("stdlib-jdk7"))
                implementation("androidx.core:core-ktx:1.2.0")
            }
        }
        val androidTest by getting {}
    }
}
This is where I get the error in both IntelliJ and gradle cli. I've also verified the gradle plugin defined for the root build.gradle.kts is
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4-M2")
and my gradle version is 6.5. I realize I might be misunderstanding something from the blog post, but hopefully someone can help clarify how this should work or look. Maybe pointing to a sample repo if one is available and known to work would help. The really odd behavior is that I can navigate from the IDE to the implementation of the ios target definition.
z
Have you tried adding?
Copy code
val iosMain by getting {
    dependencies {}
}
k
tried just now and it makes no difference and at least from my limited understanding the ios() function defines those sourceSets by default
l
Am I right that you’ve used
Multiplatform Mobile Application
template in the wizard? If so, am I right that there is still
packForXcode
task in the same
build.gradle.kts
file where the part mentioned in the original post resides? If so, that’s probably the root cause: when you replace
iosX64("ios")
call with
ios()
without updating calls in the mentioned task, it continues looking for a target customly named
ios
by the user while there is no such task:
ios()
is actually shorthand for a bit more complicated hierarchical structure and not a target itself.
k
Interesting, thanks for the pointers. I'll make some adjustments and give it a try this evening.
I was able to get this working from your suggestions @Liliia, thanks again.
👍🏻 1