hui-z / image_gallery_saver

flutter中用于保存图片到相册的Plugin
MIT License
271 stars 346 forks source link

'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 #263

Closed quoc-huynh-cosee closed 9 months ago

quoc-huynh-cosee commented 1 year ago

I'm receiving an error if I try to build/run an android app with image_gallery_saver.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':image_gallery_saver: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.
  Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 1m 49s
Exception: Gradle task assembleDebug failed with exit code 1

My app/build.gradle contains these lines, which triggers the error. These lines are added by default if we are creating a new flutter project.

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
 }

kotlinOptions {
    jvmTarget = '1.8'
}

Other packages like package_info_plus also have these lines in the android/app/build.gradle.

pastelcode commented 11 months ago

Same issue here

Collins21 commented 10 months ago

Same issue

v1ncere commented 10 months ago

I solve this problem of mine by deleting my android folder and run flutter create . which reverts back my build.gradle and make sure that you have a copy of your android folder if you have lots of modification on it.

this is my root level build.gradle buildscript:

buildscript {
    ext.kotlin_version = '1.9.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.google.gms:google-services:4.4.0'
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

app level build.gradle android:

android {
    namespace "com.example.example_app"
    compileSdkVersion 33
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        applicationId "com.example.example_app"
        minSdkVersion 23
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    buildTypes {
        release {
            signingConfig signingConfigs.debug
        }
    }
}

gradle-wrapper.properties: distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip