如何解决错误“解决失败:org.jetbrains.kotlin:kotlin-stdlib-jre7 ..."在Android Studio中构建时 [英] How to resolve error "Failed to resolve: org.jetbrains.kotlin:kotlin-stdlib-jre7..." when building in Android Studio

查看:1171
本文介绍了如何解决错误“解决失败:org.jetbrains.kotlin:kotlin-stdlib-jre7 ..."在Android Studio中构建时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过选中Android Studio 3中的"include kotlin"框创建了一个新项目,并且在开箱时编译时出现错误

I've created a new project by checking the "include kotlin" box in Android Studio 3 and out of the box I get an error while compiling

"Failed to resolve: org.jetbrains.kotlin:kotlin-stdlib-jre7..."

我确保所有插件都是最新的,并且正确安装了Android SDK.

I have made sure all plugins are up to date and that the Android SDK is properly installed.

有人知道如何解决此错误吗?

Would anyone know how to solve for this error?

推荐答案

kotlin-stdlib-jre[7/8]不久前已被弃用,此后已被删除.弃用记录会一直保留到 1.2.71 为止.发布这些工件的最新版本.官方弃用通知可以在此处找到.使用任何不推荐使用的版本(在删除之前)也应该在(至少)Android Studio和IntelliJ中产生警告.

kotlin-stdlib-jre[7/8] was deprecated a while ago, and has since been removed. The deprecation note was kept until 1.2.71, which was the last version to release those artifacts. The official deprecation notice can be found here. Using any of the deprecated versions (before it was removed) should also produce a warning in (at least) Android Studio and IntelliJ.

改为使用 kotlin-stdlib-jdk7 .它与kotlin-stdlib-jre7具有相同的依赖关系(较新的依赖除外),但已将其重命名为kotlin-stdlib-jdk. kotlin-stdlib-jre现在不再维护为单独的依赖项.

Use kotlin-stdlib-jdk7 instead. It's the same dependency as kotlin-stdlib-jre7 (except newer), but it was re-named to kotlin-stdlib-jdk. kotlin-stdlib-jre is now no longer maintained as a separate dependency.

IntelliJ和Android Studio当前都使用kotlin-stdlib-jre7生成新项目; 这可能是一个错误.他们可能尚未更新项目生成器.因此,您必须手动将依赖项替换为可用的依赖项,直到他们解决此问题为止.这取决于Kotlin插件.如果尚未更新,请进行更新. 我还没有检查是否已打补丁-如果已打补丁,那只能解决创建新项目的问题.对于从旧版本进行更新,其余答案仍然适用

Both IntelliJ and Android Studio currently generate new projects using kotlin-stdlib-jre7; this likely is a bug. They have probably not updated the project generators. Therefore, you have to manually replace the dependencies with working ones until they fix this. This is dependent on the Kotlin plugin. Update it if you haven't. I haven't checked whether it's been patched or not - if it has, that only fixes the creation of new projects. For updating from older versions, the rest of the answer still applies

如果您使用的是1.2.71或更低版本,并且要升级到1.3.0或更高版本,那么您自然就必须这样做.

You naturally have to do this if you're on 1.2.71 or lower, and you're upgrading to 1.3.0 or higher.

这些是自Kotlin 1.3.0起新的有效依赖项:

These are the new valid dependencies as of Kotlin 1.3.0:

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

其中$kotlinVersion是包含版本或硬编码版本(即1.3.0)的变量

Where $kotlinVersion is either a variable containing the version, or a hard-coded version (i.e. 1.3.0)

或者,您可以使用普通" stdlib (kotlin-stdlib),而不是特定于JDK的版本.但是您必须以任何一种方式更改依赖关系,所以我建议您使用kotlin-stdlib-jdk7,或者如果您打算使用Java 8,kotlin-stdlib-jdk8

Alternatively, you can use the "plain" stdlib (kotlin-stdlib) instead of the JDK-specific versions. But you have to change your dependency either way, so I recommend you go with kotlin-stdlib-jdk7, or if you plan on using Java 8, kotlin-stdlib-jdk8

也可以在此处. jdk7,jdk8和特定于版本的stdlib都遵循相同的版本(根据此编辑-将来可能会更改,但是在更改发生之前可能会出现通知),因此您是否检查jdk8,jdk7或常规的,所有版本都应该在stdlib工件之间通用.

The newest versions of the dependencies can also be found here. jdk7, jdk8, and the version-unspecific stdlib all follow the same versions (as per this edit - this could change in the future, but there'll likely be notices before that change happens), so whether you check jdk8, jdk7 or the regular one, all the versions should be universally available across the stdlib artifacts.

相同的实际解决方案也适用于其他构建系统,但是代码不同.由于构建系统很多,因此我将不包括所有构建系统,但是重点是将工件从kotlin-stdlib-jre[num]更改为kotlin-stdlib-jdk[num](当然没有括号).或者,如前所述,kotlin-stdlib.

The same actual solution applies to other build systems as well, but the code is different. As there are a lot of build systems, I'm not going to include all of them, but the point is changing the artifact from kotlin-stdlib-jre[num] to kotlin-stdlib-jdk[num] (without brackets of course). Or, as mentioned earlier, kotlin-stdlib.

与构建系统无关,它基于对Maven Central和类似存储库的访问.如果您的构建系统不支持此功能,并且/或者违反了Maven样式的约定和存储库,则必须找到适用于您的构建系统的内容.

Independently of the build system, this bases itself on access to Maven Central and similar repositories. If your build system doesn't support this, and/or breaks with Maven-style conventions and repositories, you'll have to find what works for your build system.

改为使用org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_versionorg.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version(取决于您最初使用的版本).

Use org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version or org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version (depending on which version you originally used) instead.

这篇关于如何解决错误“解决失败:org.jetbrains.kotlin:kotlin-stdlib-jre7 ..."在Android Studio中构建时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆