Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Failure due to JVM Target Compatibility Issue in flutter_unity_widget (Kotlin 17 vs Java 1.8) #986

Open
tsutou0224 opened this issue Sep 23, 2024 · 4 comments

Comments

@tsutou0224
Copy link

Describe the bug
When trying to run a Flutter application with the flutter_unity_widget package using "Run and Debug" in VS Code, an error occurs during the build process. The error specifically states a mismatch between the Java version for the compileDebugJavaWithJavac (targeting 1.8) and the compileDebugKotlin (targeting 17). The build fails as a result.

To Reproduce
Steps to reproduce the behavior:

  1. Open a Flutter project using the flutter_unity_widget package in VS Code.
  2. Connect an Android device running Android 12 to the PC (running Windows).
  3. Run the project using the "Run and Debug" option.
  4. Observe the error during the build process.

Expected behavior
The Flutter application should successfully run on the connected Android device without any build errors.

Error details

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flutter_unity_widget: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 9s
Error: Gradle task assembleDebug failed with exit code 1

Unity (please complete the following information):

  • OS: Windows
  • Version: 2022.3.40f1

Smartphone (please complete the following information):

  • Device: Android phone
  • OS: Android 12

Additional context

  • Flutter version: 3.24.1
  • Unity package: fuw-2022.2.0.unitypackage
  • Library: flutter_unity_widget: ^2022.2.1
@timbotimbo
Copy link
Collaborator

Which Unity version did you use, and which jvm settings are in your gradle files?

@tsutou0224
Copy link
Author

Thank you for your quick reply!

  1. Unity version: 2022.3.40f1

  2. jvm settings in my gradle files
    In the android/unityLibrary/build.gradle file, there is a section:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
}

However, I couldn't find any code specifying the JVM version in the other android/build.gradle or android/app/build.gradle files.

android/build.gradle

allprojects {
    repositories {
        flatDir {
            dirs "${project(':unityLibrary').projectDir}/libs"
        }

        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

android/app/build.gradle

plugins {
   id "com.android.application"
   id "kotlin-android"
   id "dev.flutter.flutter-gradle-plugin"
   id "com.google.gms.google-services"  // Google Services 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'
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 34
    

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

    lintOptions {
        disable 'InvalidPackage'
        checkReleaseBuilds false
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.mycompany.signlang"
        minSdkVersion 24
        targetSdkVersion 32
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

   signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }

    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 project(':unityLibrary')

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.0"
}

@prajjwalZotoAshish
Copy link

I am also getting the same issue

@mvn-khoavo-dn
Copy link

mvn-khoavo-dn commented Oct 4, 2024

Me too, I am also getting this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants