KMM项目expect声明提示JVM无actual实现但可正常构建运行
KMM项目Android Studio误报expect无对应actual声明问题
问题表现
- 项目构建、安装、运行流程全部正常,无编译级错误
- Android Studio对项目中所有
expect修饰的函数、值统一报红,提示JVM平台不存在对应的actual声明 - 代码行侧边黄色菱形的多平台跳转标识功能正常,可直接跳转查看iOS和Android端的对应
actual实现 - 所有
expect声明均触发相同报错,与声明所属包无关,已反复核对所有声明包名完全匹配 - 对比全新创建的KMM示例项目Gradle配置未发现异常,将当前项目Gradle文件完整复制到新项目中无法复现该报错


现有Gradle配置
共享模块构建配置
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) }
排查现状
已完成包名核对、Gradle配置对比、同配置新项目复现测试,暂未定位问题根因,寻求解决方向。
内容的提问来源于stack exchange,提问作者Alchitry
相关产品推荐
相关产品推荐

