本文介绍了预期的课程没有实际的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个多平台项目.

I am doing a multiplatform project.

我的gradle文件的一部分看起来像这样

A part of my gradle file looks like this

...
kotlin {
    jvm()
    jvm("api")
    js()
    mingwX64("mingw")
    sourceSets {
        ...
        val jvmMain by getting {
            dependencies {
                implementation ("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
            }
        }
        val jvmTest by getting {
            dependencies {
                implementation ("org.jetbrains.kotlin:kotlin-test")
                implementation ("org.jetbrains.kotlin:kotlin-test-junit")
            }
        }
        val apiMain by getting {
            dependencies {
                dependsOn(jvmMain)
            }
        }
        val jsMain by getting {
            dependencies {
                implementation ("org.jetbrains.kotlin:kotlin-stdlib-js")
            }
        }
        ...
    }
}

现在commonsMain来源中,我收到一个IDE错误(红色下划线),上面写着期望的类Sample在apiMain中没有实际的声明",但是apiMain依赖于具有实际声明的jvmMain.

Now in the commonsMain sources I get an IDE error (red underline) that says "expected class Sample has no actual declaration in apiMain", but apiMain depends on jvmMain which has the actual declaration.

我认为apiMain中不需要实际的声明,因为我在jvm中已经有一个声明.

I don't think I need an actual declaration in apiMain since I already have one in jvm.

在设置源集时我应该采取其他方法吗?

Should I take a different approach in setting-up my source sets?

无论如何项目都可以正常编译,并且我可以运行apiMain,但是IDE错误确实使我烦恼.

Anyway the project compiles fine and I can run apiMain, but the IDE error really annoys me.

推荐答案

这是一个已知的IDE错误.请在此处查看YouTrack票.

This is a known IDE bug. See YouTrack ticket here.

现在,您可以使用 @Suppress("NO_ACTUAL_FOR_EXPECT")来消除IDE中的警告.请确保进行彻底测试,以确保您确实没有错过任何 actual 实现.

For now, you can use @Suppress("NO_ACTUAL_FOR_EXPECT") to get rid of the warning in your IDE. Be sure to test thoroughly to ensure you really aren't missing any actual implementations.

这篇关于预期的课程没有实际的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 09:51