如何解决错误“无法解决: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

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

问题描述

我通过选中 Android Studio 3 中的包含 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.

我该如何解决这个错误?

How can I 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)

或者,您可以使用普通"标准库(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天全站免登陆