Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Resolved Gradle Build Failed (2021.3.5f1, lambda expressions are not supported in -source 1.7)

Discussion in 'Android' started by VRPlayrion, Jul 26, 2022.

  1. VRPlayrion

    VRPlayrion

    Joined:
    Feb 24, 2021
    Posts:
    4
    Hi !

    Since we updated our project to 2021.3.5f1, we have the error below while building on Android.
    We did not have issue on 2021.1.28f1.
    If I remove the UnityMobileNotification package (containing the lambda expression not supported), the build succeed.

    It looks like the version of the JDK used during the build process is not recent enough.
    In the Preferences -> External Tools, the JDK used is the one recommended (the one from 2021.3.5f1 : OpenJDK 1.8.0_152).

    Do you have any clue of the origin of this issue?

    Thanks!

    Console:

    CommandInvokationFailure: Gradle build failed.
    /Applications/Unity/Hub/Editor/2021.3.5f1/PlaybackEngines/AndroidPlayer/OpenJDK/bin/java -classpath "/Applications/Unity/Hub/Editor/2021.3.5f1/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-6.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx8192m" "assembleRelease"
    stderr[
    Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
    /Users/MyProject/Library/Bee/Android/Prj/IL2CPP/Gradle/unityLibrary/src/main/java/com/unity/androidnotifications/UnityNotificationManager.java:376: error: lambda expressions are not supported in -source 1.7
    Thread housekeepingThread = new Thread(() -> {
    ^
    (use -source 8 or higher to enable lambda expressions)
    1 error
    FAILURE: Build failed with an exception.
    * What went wrong:
    Execution failed for task ':unityLibrary:compileReleaseJavaWithJavac'.
    > Compilation failed; see the compiler error output for details.
    * 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 5m 21s
     
  2. VRPlayrion

    VRPlayrion

    Joined:
    Feb 24, 2021
    Posts:
    4
    Some more news about the issue :
    - the problem is not local (other computers with the same project have the same build failure)
    - build is working on iOS
    - an build android on a separate project with only the notification package on 2021.3.5f1 is working


    More logs during the build process :

    Done: apply plugin: 'com.android.application'
    dependencies {
    implementation project(':unityLibrary')
    }
    android {
    compileSdkVersion 31
    buildToolsVersion '30.0.2'
    compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }
    defaultConfig {
    minSdkVersion 22
    targetSdkVersion 31
    applicationId 'XXXX'
    ndk {
    abiFilters 'armeabi-v7a', 'arm64-v8a'
    }
    versionCode XXXXX
    versionName 'XXXXX'
    multiDexEnabled true
    }
    aaptOptions {
    noCompress = ['.unity3d', '.ress', '.resource', '.obb', '.bundle', '.unityexp'] + unityStreamingAssets.tokenize(', ')
    ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    }
    signingConfigs {
    release {
    [...] (some keystore info here)
    }
    }
    lintOptions {
    abortOnError false
    }
    buildTypes {
    debug {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt')
    signingConfig signingConfigs.release
    jniDebuggable true
    }
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt')
    signingConfig signingConfigs.release
    }
    }
    packagingOptions {
    doNotStrip '*/armeabi-v7a/*.so'
    doNotStrip '*/arm64-v8a/*.so'
    }
    bundle {
    language {
    enableSplit = false
    }
    density {
    enableSplit = false
    }
    abi {
    enableSplit = true
    }
    }
    }
     
  3. VRPlayrion

    VRPlayrion

    Joined:
    Feb 24, 2021
    Posts:
    4
    Issue solved :

    We used both a custom mainTemplate.gradle and launcherTemplate.gradle.
    CompileOptions were correctly set on the launcherTemplate, but missing on the mainTemplate.
    Adding those lines on the mainTemplate.gradle solved the issue.

    Code (CSharp):
    1. compileOptions
    2. {
    3. sourceCompatibility JavaVersion.VERSION_1_8
    4. targetCompatibility JavaVersion.VERSION_1_8
    5. }
     
  4. Athomield3D

    Athomield3D

    Joined:
    Aug 29, 2012
    Posts:
    193
    when I change sourceCompatibility to JavaVersion.VERSION_1_8, it keeps going back to JavaVersion.VERSION_1_7 when I hit build
     
  5. zoidxwell

    zoidxwell

    Joined:
    Jun 1, 2020
    Posts:
    2
    Same problem. Has anyone already solved this?
    Unity editor 2021.3.8.f1
     
  6. zoidxwell

    zoidxwell

    Joined:
    Jun 1, 2020
    Posts:
    2
    I had to upgrade Unity editor to a newer version (2021.3.18.f1) to get this resolved
     
  7. TitanBornStudios

    TitanBornStudios

    Joined:
    Nov 4, 2019
    Posts:
    4
    Same. Thanks!