Hello. I am having problems when referencing third...
# multiplatform
m
Hello. I am having problems when referencing third party libraries in the
common
source folder. I have added
kotlinx.serialization
and am using it successfully in the app. However in the AndroidStudio source editor all classes from the serialization library are marked as unresolved and no tooling works for them. Is anybody aware of such an issue?
a
you might need to install/apply the kotlinx.serialization gradle plugin
Copy code
plugins {
    kotlin("plugin.serialization") version "1.7.20"
}
m
The issue applies to all third party dependencies declared in the commons dependency section not only serialization. I am also using the libraries. So everything compiles fine but the tooling is missing.
a
I see. If it builds correctly, I'm pretty sure that means the model is correct. So you might need to manually sync your gradle project, or invalidate the IDE's caches and restart (you can find both of those in the actions search menu)
m
Did all of the above. To no success.
a
:(
e
What version of AS are you using?
m
that is on AS canary
Just opened the project on AS beta. Same issue.
and also on AS stable
e
I usually have to apply this hack to get AS to work
Copy code
/**
 * apply this hack for Android Studio because AGP and KGP aren't handling it correctly yet
 *
 * [Kotlin Slack](<https://kotlinlang.slack.com/archives/C3PQML5NU/p1652777328313809|https://kotlinlang.slack.com/archives/C3PQML5NU/p1652777328313809>)
 *
 * [Issue Tracker](<https://issuetracker.google.com/issues/231701341|https://issuetracker.google.com/issues/231701341>)
 */
public fun KotlinMultiplatformExtension.androidStudioHackForCommonMain() {
  sourceSets.configureEach {
    if(name == "androidMain") {
      kotlin.srcDir("src/commonMain/kotlin")
    }
  }
}
m
@eygraber I am not sure where to apply this function. Could you give me a hint?
e
You can put the body of that function in your
kotlin
block
m
@eygraber Unfortunately this did not help.
opening the project in stable IntelliJ and setting the android gradle plugin version to its max supported value of 7.2.0 does resolve the common dependencies correctly
Opening the project in AS canary (with kmm plugin installed) but keeping the android gradle plugin at 7.2.0 does again not resolve the dependencies correctly.
a
Try invalidate cache and restart