【问题标题】:annotation are not supported at language level 1.3 android studio语言级别 1.3 android studio 不支持注释
【发布时间】:2020-03-01 08:16:29
【问题描述】:
我在 android studio 3.5.3 中使用 kotlin 1.3.11 创建新项目
问题是我构建项目时出现此错误
错误
错误:-source 1.3 不支持注释
(使用 -source 5 或更高版本来启用泛型)
或者这个
错误:-source 1.3 不支持泛型
(使用 -source 5 或更高版本来启用泛型)
保持错误时在源代码中显示此内容
语言级别 1.3 不支持注释
此错误也适用于 Dagger 生成的文件
【问题讨论】:
标签:
android
android-studio
kotlin
build
【解决方案1】:
这是因为您的 kotlin 使用 java 1.3 编译器。
对于修复,您可以将其添加到 build/gradle
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
或
所有项目的其他方式修复。
- 打开 IntelliJ 首选项
- 转到构建、执行、部署 > 编译器 > Kotlin 编译器但是
其他设置 > Kotlin 编译器,如果 Android Studio > 3.4
- 将目标 JVM 版本更改为 1.8
- 点击应用
【解决方案2】:
一段时间后我找到了解决方案
只需将其添加到build.gradle
android {
...
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}