我在 android Gradle 中遇到版本问题

I am getting version issues in android Gradle

提问人:Shameer taggar 提问时间:10/17/2023 更新时间:10/17/2023 访问量:35

问:

当我尝试构建我的应用程序时,我收到以下错误:

任务“:app:kaptGenerateStubsDebugKotlin”执行失败。

“compileDebugJavaWithJavac”任务(当前目标是 1.8)和“kaptGenerateStubsDebugKotlin”任务(当前目标是 17) jvm 目标兼容性应设置为相同的 Java 版本。 考虑使用 JVM 工具链:https://kotl.in/gradle/jvm/toolchain

  • 尝试:

使用 --stacktrace 选项运行以获取堆栈跟踪。 使用 --info 或 --debug 选项运行以获取更多日志输出。 使用 --scan 运行以获取完整的见解。

Build.gradle (项目)

 buildscript {
    ext {
        compose_ui_version = '1.4.0'
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.3.15'
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.5.3"
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '8.0.0' apply false
    id 'com.android.library' version '8.0.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
    id 'com.google.dagger.hilt.android' version '2.44' apply false
}

Build.gradle(应用)

android {
    namespace 'com.sturec.sturecadmin'
    compileSdk 33

    defaultConfig {
        applicationId "com.sturec.sturecadmin"
        minSdk 26
        targetSdk 33
        versionCode 7
        versionName "1.1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary 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 = '1.8'
    }
    buildFeatures {
        viewBinding true
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.4.0'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}
android kotlin android-gradle-plugin build.gradle

评论


答:

0赞 ΓDΛ 10/17/2023 #1

您可以从设置中选择 Gradle,然后选择相关版本。

Gradle settings jdk

0赞 Pablo Iglesias 10/17/2023 #2

如果要在代码中更改它,请转到 Build.gradle(app) 并更改行

    kotlinOptions {
    jvmTarget = '1.8'
}

到您实际定位的版本(根据您发布的错误消息为 17)