alexrintt / shared-storage

Flutter plugin to work with Android external storage.
http://alexrintt.io/shared-storage/
MIT License
53 stars 24 forks source link

Compilation error due to mismatch between compileDebugJavaWithJavac and compileDebugKotlin #157

Open acheronian opened 3 months ago

acheronian commented 3 months ago

This issue started happening after upgrading my Kotlin version to 1.9.22 and Gradle plugin to 8.1.1.

Whenever I try to run the app on Android devices or Android emulator (no issues with iOS), I get this error message during assembleDebug:

Error: unable to find directory entry in pubspec.yaml: D:\Repositories\pocket-house-flutter-app-frontend\frontend_pockethouse\packages\pockethouse_classic\res\
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: D:\pub-cache\hosted\pub.dev\firebase_messaging-14.8.0\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':shared_storage:compileDebugKotlin'.
> Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlin' (17).

  Consider using JVM Toolchain: https://kotl.in/gradle/jvm/toolchain
  Learn more about JVM-target validation: https://kotl.in/gradle/jvm/target-validation 

* 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 58s
Error: Gradle task assembleDebug failed with exit code 1

Current workaround (PROJECT/android/build.gradle):

rootProject.buildDir = '../build'
subprojects {
  afterEvaluate {
        if (project.plugins.hasPlugin("com.android.application")
                || project.plugins.hasPlugin("com.android.library")) {

            if (project.name == "shared_storage") {
                project.android.compileOptions {
                    sourceCompatibility = JavaVersion.VERSION_17
                    targetCompatibility = JavaVersion.VERSION_17
                }
            }
        }
    }
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}

Updating build.gradle config for newest java and gradle version would be great 👍