首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【错误记录】Android Studio 编译报错 ( e: Unknown JVM target version: 1.9 Supported versions: 1.6, 1.8, 9, 10 )

【错误记录】Android Studio 编译报错 ( e: Unknown JVM target version: 1.9 Supported versions: 1.6, 1.8, 9, 10 )

作者头像
韩曙亮
发布2023-03-26 09:37:50
发布2023-03-26 09:37:50
4.3K0
举报

文章目录

一、错误记录


在 Android Studio 中编译执行 Android 工程 , 报如下错误 :

e: Unknown JVM target version: 1.9

Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18

Task :app:compileDebugKotlin FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:app:compileDebugKotlin’. A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction Compilation error. See log for more details

完整报错信息 :

代码语言:javascript
复制
> Task :app:compileDebugKotlin
'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 1.9) jvm target compatibility should be set to the same Java version.
e: Unknown JVM target version: 1.9
Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18

> Task :app:compileDebugKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugKotlin'.


* Get more help at https://help.gradle.org

BUILD FAILED in 2m 2s
30 actionable tasks: 30 executed

二、解决方案


报错的核心问题 , 发现未知的 Java 虚拟机版本 1.9 , 支持的 JVM 版本号只能是 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 中的版本号 ;

代码语言:javascript
复制
e: Unknown JVM target version: 1.9
Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18

在 Settings 设置中 , 设置的 JDK 版本是 11 版本的 ;

在 build.gradle 中 , 发现有 如下设置 , 其中设置了 jvmTarget 为 1.9 版本 ;

代码语言:javascript
复制
android {
    namespace 'kim.hsl.databinding_demo'
    compileSdk 32
    
    kotlinOptions {
        jvmTarget = '1.9'
    }
}

这是由 Android Studio 自动生成的版本 , 居然报错 ;

将该版本修改为 9 , kotlinOptions { jvmTarget = ‘9’ } 然后重新编译 , 编译通过 ;

核心文件代码示例 :

代码语言:javascript
复制
android {
    namespace 'kim.hsl.databinding_demo'
    compileSdk 32
    
    kotlinOptions {
        jvmTarget = '9'
    }
}

修改后的完整配置文件 :

代码语言:javascript
复制
plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'kim.hsl.databinding_demo'
    compileSdk 32

    defaultConfig {
        applicationId "kim.hsl.databinding_demo"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        // 启用 DataBinding
        dataBinding {
            enabled = true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '9'
    }
}

dependencies {
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-03-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • 一、错误记录
  • 二、解决方案
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档