https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
v

Vaibhav Jaiswal

11/02/2023, 9:49 AM
Hey everyone I upgraded Kotlin Version to 1.9.20 But now in Shared Module build.gradle.kts, I’m getting these error on Sync
Copy code
e: file:///Volumes/Files/Medial/MedialMultiplatform/shared/build.gradle.kts:18:5: Unresolved reference: androidTarget
e: file:///Volumes/Files/Medial/MedialMultiplatform/shared/build.gradle.kts:93:9: Unresolved reference: androidMain
e: file:///Volumes/Files/Medial/MedialMultiplatform/shared/build.gradle.kts:119:9: Unresolved reference: iosMain
This is my project Gradle
Copy code
plugins {
    //trick: for the same plugin versions in all sub-modules
    id("com.android.application").version("8.2.0-beta06").apply(false)
    id("com.android.library").version("8.2.0-beta06").apply(false)
    kotlin("multiplatform").version(libs.versions.kotlin.get()).apply(false)
    id("com.codingfeline.buildkonfig").version("0.14.0").apply(false)
    kotlin("plugin.serialization").version("1.4.21").apply(false)
    id("org.jetbrains.compose").version(libs.versions.compose.get()).apply(false)
    id("com.google.gms.google-services").version("4.3.14").apply(false)
    alias(libs.plugins.crashlytics).apply(false)
}
Shared Gradle
Copy code
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING
plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    id("com.android.library")
    id("app.cash.sqldelight") version "2.0.0"
    kotlin("plugin.serialization")
    id("com.codingfeline.buildkonfig")
    id("org.jetbrains.compose")
    id("dev.icerock.mobile.multiplatform-resources")
}

@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class)
kotlin {
    jvmToolchain(11)
    androidTarget()
    iosArm64()
    iosSimulatorArm64()

    cocoapods {
        summary = "Some description for the Shared Module"
        homepage = "Link to the Shared Module homepage"
        version = "1.0"
        ios.deploymentTarget = "14.1"
        podfile = project.file("../iosApp/Podfile")
        framework {
            baseName = "shared"
            isStatic = true
        }

        pod("Amplitude", "8.17.1")
        pod("FirebaseMessaging")
        pod("FirebaseAuth")
        pod("Reachability")
        pod("GoogleSignIn")
        pod("lottie-ios") {
            version = "4.3.3"
            moduleName = "Lottie"
        }
    }
    
    sourceSets {
       
        commonMain {
            dependencies {
                ………………….
            }
        }

        commonMain {
            dependencies {
                implementation(kotlin("test"))
            }
        }

        androidMain {
            dependencies {
                ……………………….
            }
        }

        iosMain {
            dependencies {
                ………………….
            }
        }
    }
}
c

Chrimaeon

11/02/2023, 9:59 AM
this build files are not using the kotlin dsl. for
getting
the configurations you need to use something like
val androidMain by getting
v

Vaibhav Jaiswal

11/02/2023, 9:59 AM
Even in Kotlin 1.9.20?
c

Chrimaeon

11/02/2023, 10:00 AM
yes, your syntax is groovy.
v

Vaibhav Jaiswal

11/02/2023, 10:01 AM
@Chrimaeon https://kotlinlang.org/docs/whatsnew1920.html#use-completion-for-source-sets This shows we can use it without
by getting
It’s not detecting
androidTarget
too
c

Chrimaeon

11/02/2023, 10:14 AM
It doesn’t say that this is Kotlin dsl.
v

Vaibhav Jaiswal

11/02/2023, 10:16 AM
Okay, so I tried with
getting
this is what I get while syncing
Copy code
After that, replace `by getting` with static accessors:

  sourceSets {
      commonMain { ... }
      
      iosMain {
          dependencies { ... }
      }
  }
c

Chrimaeon

11/02/2023, 10:22 AM
then I’m out of ideas.
v

Vaibhav Jaiswal

11/02/2023, 10:22 AM
No issues, thanks for helping out
c

Chrimaeon

11/02/2023, 10:23 AM
what is the sentance before
After that
? did you doo that?
v

Vaibhav Jaiswal

11/02/2023, 10:33 AM
to not use
ios()
and rather specify
iOSArm64()
etc ..
These are just warnings
c

Chrimaeon

11/02/2023, 10:34 AM
👍
j

Jeff Lockhart

11/02/2023, 3:51 PM
This is correct, you can use static accessors for default hierarchy template source sets instead of
by getting
with Kotlin 1.9.20. I'm assuming this:
Copy code
commonMain {
    dependencies {
        implementation(kotlin("test"))
    }
}
is actually:
Copy code
commonTest {
    dependencies {
        implementation(kotlin("test"))
    }
}
I'd make sure you're running the latest version of plugins and dependencies. In this case there was an issue because of the Build Konfig plugin, which it looks like you are using as well.
v

Vaibhav Jaiswal

11/02/2023, 4:26 PM
@Jeff Lockhart I’ve tried by removing buildKonfig as well, commonMain and commonTest are wokring, but its still unable to detect androidMain and iosMain, as well as androidTarget
d

dsavvinov

11/02/2023, 4:45 PM
It seems like for some reason you’re actually getting a version of KGP older than 1.9.20. This can happen if other Gradle plugins have “hard” dependencies on KGP and if they are not updated. It’s hard to be more precise without having a full access to buildscripts (settings.gradle.kts, convention plugins if any, etc.)
v

Vaibhav Jaiswal

11/02/2023, 6:35 PM
The Android Studio version I’m using Hedgehog Beta 6, it has Kotlin Plugin 1.9.10, can this be the cause?
j

Jeff Lockhart

11/02/2023, 6:40 PM
The Kotlin IDE plugin shouldn't affect the actual build.
v

Vaibhav Jaiswal

11/02/2023, 7:11 PM
@लातों वाला भूत
22 Views