Home > Back-end >  How to resolve Android Build error "Your build is currently configured to use Java 19 and Gradl
How to resolve Android Build error "Your build is currently configured to use Java 19 and Gradl

Time:01-05

My Android project was building fine with the following project build file

buildscript {
    ext {
        compose_version = '1.4.0-alpha02'
    }
}

plugins {
    id 'com.android.application' version '8.0.0-alpha10' apply false
    id 'com.android.library' version '8.0.0-alpha10' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.21' apply false
    id 'com.google.dagger.hilt.android' version '2.44.2' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

my Android Studio version is

Android Studio Flamingo | 2022.2.1 Canary 10
Build #AI-222.4459.24.2221.9409768, built on December 15, 2022
Runtime version: 17.0.4.1 0-17.0.4.1b469.62-9127311 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 10.15.7
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 12
Metal Rendering is ON
Registry:
    external.system.auto.import.disabled=true
    ide.text.editor.with.preview.show.floating.toolbar=false
    gradle.version.catalogs.dynamic.support=true
    ide.images.show.chessboard=true

Non-Bundled Plugins:
    com.android.aas (3.5.1)
    com.jetbrains.kmm (0.5.1(222)-30)

My Android application is a multi module project with each module setting the following java/kotlin options

compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
    coreLibraryDesugaringEnabled true
}
kotlinOptions {
    jvmTarget = '11'
    freeCompilerArgs  = [
            "-opt-in=androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi"]
}

Within my Android Studio preferences I set Gradle JDK: Java 18

However when I make the following change to my app gradle build file

compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
    coreLibraryDesugaringEnabled true
}
kotlinOptions {
    jvmTarget = '11'
    freeCompilerArgs  = [
            "-opt-in=androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi",
            "-opt-in=kotlinx.coroutines.ObsoleteCoroutinesApi",
    ]
}

e.g. add this additional -opt-in entry "-opt-in=kotlinx.coroutines.ObsoleteCoroutinesApi",

my build fails with

Starting Gradle Daemon...
Gradle Daemon started in 3 s 350 ms

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not open cp_proj generic class cache for build file '/Users/anonymous/github/mobile-android-app/app/build.gradle' (/Users/beecheya/.gradle/caches/7.5/scripts/3am3ttbat0qsqgsjlhtiaj5se).
   > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 63

and also

Unsupported Java. 
Your build is currently configured to use Java 19 and Gradle 7.5.

Possible solution:
 - Open Gradle wrapper settings, change `distributionUrl` property to use compatible Gradle version and reload the project

my gradle wrapper contents resemble this:-

#Tue Oct 25 07:38:32 BST 2022
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

How do i resolve this build error?

What have I done wrong?

CodePudding user response:

Update to Gradle 7.6 that has Java 19 support.

See https://docs.gradle.org/7.6/release-notes.html#java19

  • Related