gradle Android Studio构建错误-compilegJavaWithJavac任务(当前目标为1.8)和compilegKotlin任务(当前目标为17)f

nc1teljy  于 2023-11-18  发布在  Android
关注(0)|答案(2)|浏览(306)

我正在开发一个应用程序,它一直运行良好,直到我升级了gradle版本,现在这是错误。我也试图将版本更改为17,但它似乎不工作,并在设置android studio为17时更改了gradle的java版本。

Execution failed for task ':stripe_android:compileDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' 
task (current target is 17) jvm target compatibility should be set to the same Java 
version.

字符串
这是我的buld.gradle文件。在这里我根据错误进行了更改。

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

android {
    namespace "com.roam1.esim"
    compileSdkVersion flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = '17'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.sim"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion 21
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation 'com.facebook.android:facebook-android-sdk:latest.release'
    implementation platform('com.google.firebase:firebase-bom:32.4.0')
    implementation 'com.google.firebase:firebase-analytics-ktx'
}

ecbunoof

ecbunoof1#

这个错误是因为你试图使用Java 17而不是Java 8。
在您的build.gradle

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = '1.8'
}

字符串
检查:
Settings -> Build, Execution, Deployment -> Build Tools -> Gradle
检查Gradle JDK是否设置为1.8

dhxwm5r4

dhxwm5r42#

在您的bulid.gradle更新中,

//project level
 id 'org.jetbrains.kotlin.android' version '1.9.10' apply false

//app level
    composeOptions {
        kotlinCompilerExtensionVersion '1.5.3'
    }

字符串

相关问题