Alchitry
Alchitry

Reputation: 1549

KMM Project: Expected class has no actual declaration in module for JVM

I have a KMM project that is working perfectly except Android Studio gives an error on every expect function/value in my project complaining the actual version of it doesn't exist for JVM.

enter image description here

The A in a yellow diamond to the side of it shows both the iOS and Android actual versions and the project builds/runs just fine.

enter image description here

I've double checked package names and it happens with every expect regardless of the package.

I've looked over my gradle build files and can't find anything weird when comparing them to a new KMM example project.

plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    id("com.android.library")
    id("com.rickclephas.kmp.nativecoroutines") version "0.12.2-new-mm"
}

version = "1.0"

kotlin {
    android()
    iosX64()
    iosArm64()
    //iosSimulatorArm64() sure all ios dependencies support this target

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

    sourceSets {
        val ktorVersion = "2.0.2"

        val commonMain by getting {
            dependencies {
                implementation("com.litclimbing:firebase-auth:+")
                implementation("com.litclimbing:firebase-firestore:+")
                implementation("com.litclimbing:buffer:+")

                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")

                implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")

                implementation("io.ktor:ktor-client-core:$ktorVersion")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.4.1")
                implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1")
                implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
            }
        }
        val androidTest by getting

        val iosX64Main by getting
        val iosArm64Main by getting
        //val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            //iosSimulatorArm64Main.dependsOn(this)
            dependencies {
                implementation("io.ktor:ktor-client-darwin:$ktorVersion")
            }
        }
        val iosX64Test by getting
        val iosArm64Test by getting
        //val iosSimulatorArm64Test by getting
        val iosTest by creating {
            dependsOn(commonTest)
            iosX64Test.dependsOn(this)
            iosArm64Test.dependsOn(this)
            //iosSimulatorArm64Test.dependsOn(this)
        }
    }

    sourceSets.all {
        languageSettings.optIn("kotlin.RequiresOptIn")
        languageSettings.optIn("kotlin.ExperimentalUnsignedTypes")
    }
}

android {
    compileSdk = 32
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdk = 29
        targetSdk = 32
    }
}
buildscript {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
        classpath("com.android.tools.build:gradle:7.2.1")
        classpath("com.google.gms:google-services:4.3.10")
        classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.0")
    }
}

allprojects {
    repositories {
        google()
        mavenLocal()
        mavenCentral()
        maven {
            setUrl("https://jitpack.io")
        }
        maven {
            setUrl("https://maven.pkg.jetbrains.space/public/p/kotlinx-coroutines/maven")
        }
    }
}

tasks.register("clean", Delete::class) {
    delete(rootProject.buildDir)
}

I've even tried copying the gradle files to a new KMM project to see if it would break it and it didn't so I'm at a loss of where to even look.

Upvotes: 10

Views: 2947

Answers (1)

Alchitry
Alchitry

Reputation: 1549

Not really the solution I was looking for but it seems to be a bug in Android Studio/IntelliJ and not the gradle setup.

To fix it do the following.

  1. Close Android Studio
  2. Open your project folder in the file browser
  3. Rename the .idea folder to .ideaBackup
  4. Reopen the project
  5. Assuming everything is now working, delete .ideaBackup
  6. Enjoy your lack of random errors

Upvotes: 5

Related Questions