我试图将一个java类转换为Kotlin,除了我得到以下错误之外,它工作正常。我试图重新下载所有依赖项,如下面的suggessted,但无济于事。请帮我解决这个错误。
错误:
Error:(2, 0) Unable to find method 'org.gradle.api.internal.file.DefaultSourceDirectorySet.<init>(Ljava/lang/String;Lorg/gradle/api/internal/file/FileResolver;)V'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
<a href="syncProject">Re-download dependencies and sync project (requires network)</a></li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
<a href="stopGradleDaemons">Stop Gradle build processes (requires restart)</a></li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
答案 0 :(得分:4)
尝试在build.gradle中更新kotlin版本。
ext.kotlin_version = '1.3.72'
答案 1 :(得分:0)
虽然答案迟了,但可能会对某人有所帮助。下面为我工作。
在Android Studio中再次配置Kotin→首选项…→插件→浏览存储库→在搜索框中键入“ Kotlin”→安装/更新。
然后重新启动Android Studio,并从头开始重复Android Studio→工具→“在项目中配置Kotlin”
答案 2 :(得分:0)
在我的情况下,我遇到了错误,因为Kotlin Gradle插件的版本与Kotlin Android Studio插件中配置的版本不同。
更新Kotlin Gradle插件的版本以匹配另一个插件解决了该问题。
您可以在Preferences / Languages & Frameworks / Kotlin Updates
应该与您所拥有的相同:
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"