当前位置:   article > 正文

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

inconsistent jvm-target compatibility detected for tasks 'compiledebugjavawi





一、错误记录



在 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

完整报错信息 :

> 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26




二、解决方案



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

e: Unknown JVM target version: 1.9
Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18
  • 1
  • 2

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

在这里插入图片描述

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

android {
    namespace 'kim.hsl.databinding_demo'
    compileSdk 32
    
    kotlinOptions {
        jvmTarget = '1.9'
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

在这里插入图片描述

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

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

核心文件代码示例 :

android {
    namespace 'kim.hsl.databinding_demo'
    compileSdk 32
    
    kotlinOptions {
        jvmTarget = '9'
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

修改后的完整配置文件 :

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'
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/639694
推荐阅读
相关标签
  

闽ICP备14008679号