android studio 中的 Kotlin 插件错误
Kotlin plugin error in android studio
我正在尝试为 android studio 设置 kotlin 插件并关注 this guide。一切都编译得很好,我可以在我的项目中使用 .kt
文件。但是,在每个 kotlin 文件中 android-studio 都说明如下:
Kotlin library 'compiler-1.0-rc1.jar' has an unsupported format. Please update library or plugin
如何删除这个 warning/error?
这是我的顶层 build.gradle
:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'me.tatarka:gradle-retrolambda:3.2.3'
classpath "com.android.databinding:dataBinder:1.0-rc1"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.14.449'
}
}
allprojects {
repositories {
mavenCentral()
jcenter()
}
}
这是我在 app
目录中的 build.gradle
:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
//Ommited for brevity
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile 'org.jetbrains.kotlin:kotlin-stdlib:0.14.449'
}
我正在使用 Android studio 1.4,
buildToolsVersion 23.0.1,
Android studio kotlin 插件版本 0.14.449.Idea141.12
数据绑定库的当前版本正在使用 kotlin。我相信您看到的消息是因为该库使用的是 kotlin 版本 0.12.613。
reddit 上对此进行了一些讨论。
您可以尝试更新到最新版本的数据绑定库1.0-rc4,看看它们是否已经更新到 M14。
其他答案涵盖了这个特定库的基础知识。但总的来说:
关于错误信息...
当 Kotlin 创建的 class 文件的 ABI 版本号与 Kotlin 编译器使用的预期版本号不匹配时,会出现 "unsupported format" 错误。这不再是 Kotlin 1.0 Betas 的问题,因为 ABI 编号不会在 1.0 中再次更改。但是,在 1.0 候选发布版中将进行一次强制重新编译,以确保没有旧的编译器错误影响库或代码,并且一切都重建干净。之后就不会再有这样的问题了。
因此,如果库不是具有相同 ABI 的最新版本,或者遇到最后的“1.0 重新编译”,您可能 运行 会出现类似的错误。解决方案总是找到更新的库。
在 Kotlin 1.0 Beta 4 announcement "What's Next" 部分中有更多相关信息:
After the Beta period is over, there will an RC and then 1.0.
We would really like to make sure that no code compiled with
pre-release versions of Kotlin are kept around after 1.0, so the RC
compiler will force recompilation of all the old code. We will
coordinate with library maintainers outside JetBrains to make sure
that all the widely-used libraries will be recompiled in time.
We’ll also take the opportunity to remove some legacy at this point:
- remove all the deprecations that we have accumulated in the process of evolving our libraries,
- remove all the deprecations from the generated code (you might not have heard of those, but they exist!),
- get rid of some legacy bytecode peculiarities that were found during the beta,
- move some of the stdlib code around so that the packages there have
more structure.
After that point, the only compatible changes to the
standard library are deprecations and additions (this does not include
reflection APIs). We are running an open review for the library API to
make sure we haven’t missed anything important.
我正在尝试为 android studio 设置 kotlin 插件并关注 this guide。一切都编译得很好,我可以在我的项目中使用 .kt
文件。但是,在每个 kotlin 文件中 android-studio 都说明如下:
Kotlin library 'compiler-1.0-rc1.jar' has an unsupported format. Please update library or plugin
如何删除这个 warning/error?
这是我的顶层 build.gradle
:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'me.tatarka:gradle-retrolambda:3.2.3'
classpath "com.android.databinding:dataBinder:1.0-rc1"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.14.449'
}
}
allprojects {
repositories {
mavenCentral()
jcenter()
}
}
这是我在 app
目录中的 build.gradle
:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
//Ommited for brevity
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile 'org.jetbrains.kotlin:kotlin-stdlib:0.14.449'
}
我正在使用 Android studio 1.4,
buildToolsVersion 23.0.1,
Android studio kotlin 插件版本 0.14.449.Idea141.12
数据绑定库的当前版本正在使用 kotlin。我相信您看到的消息是因为该库使用的是 kotlin 版本 0.12.613。
reddit 上对此进行了一些讨论。
您可以尝试更新到最新版本的数据绑定库1.0-rc4,看看它们是否已经更新到 M14。
其他答案涵盖了这个特定库的基础知识。但总的来说:
关于错误信息...
当 Kotlin 创建的 class 文件的 ABI 版本号与 Kotlin 编译器使用的预期版本号不匹配时,会出现 "unsupported format" 错误。这不再是 Kotlin 1.0 Betas 的问题,因为 ABI 编号不会在 1.0 中再次更改。但是,在 1.0 候选发布版中将进行一次强制重新编译,以确保没有旧的编译器错误影响库或代码,并且一切都重建干净。之后就不会再有这样的问题了。
因此,如果库不是具有相同 ABI 的最新版本,或者遇到最后的“1.0 重新编译”,您可能 运行 会出现类似的错误。解决方案总是找到更新的库。
在 Kotlin 1.0 Beta 4 announcement "What's Next" 部分中有更多相关信息:
After the Beta period is over, there will an RC and then 1.0.
We would really like to make sure that no code compiled with pre-release versions of Kotlin are kept around after 1.0, so the RC compiler will force recompilation of all the old code. We will coordinate with library maintainers outside JetBrains to make sure that all the widely-used libraries will be recompiled in time.
We’ll also take the opportunity to remove some legacy at this point:
- remove all the deprecations that we have accumulated in the process of evolving our libraries,
- remove all the deprecations from the generated code (you might not have heard of those, but they exist!),
- get rid of some legacy bytecode peculiarities that were found during the beta,
- move some of the stdlib code around so that the packages there have more structure.
After that point, the only compatible changes to the standard library are deprecations and additions (this does not include reflection APIs). We are running an open review for the library API to make sure we haven’t missed anything important.