Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find method: coreLibraryDesugaringEnabled in the gradle

I want to use Android Studio 4.0 Canary 3

as in the, features list has mentioned:

Android Studio now includes support for using a number of Java 8 language APIs without requiring a minimum API level for your app.

with adding this method coreLibraryDesugaringEnabled with a true argument into the compileOptions object, in the module’s build.gradle file.

like this:

 compileOptions {
    // Flag to enable support for the new language APIs
    coreLibraryDesugaringEnabled true
    // Sets Java compatibility to Java 8
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

I expected it would work fine, but it makes the below error:

Could not find method coreLibraryDesugaringEnabled() for arguments [true] on object of type com.android.build.gradle.internal.CompileOptions.

like image 284
Ali Rezaiyan Avatar asked Nov 25 '19 10:11

Ali Rezaiyan


4 Answers

Answer from dankawka on https://github.com/juliuscanute/qr_code_scanner/issues/325, read to make sure your problem is actually the same.

You have to upgrade Gradle, Kotlin and Kotlin Gradle Plugin:

  • In android/build.gradle bump ext.kotlin_version = '1.3.50' to ext.kotlin_version = '1.5.10'
  • In android/build.gradle bump classpath 'com.android.tools.build:gradle:3.5.0' to classpath 'com.android.tools.build:gradle:4.2.0'
  • In android/gradle/wrapper/gradle-wrapper.properties bump distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip to distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
like image 74
Marvioso Avatar answered Oct 17 '22 10:10

Marvioso


What about if you use isCoreLibraryDesugaringEnabled?

like image 39
Giorgos Kylafas Avatar answered Oct 28 '22 03:10

Giorgos Kylafas


You should use latest Gradle service version > 6.3 (Gradle wrapper file) and Gradle build version > 4.1.0 alpha (app.gradle file) in order to work desugaring.

Here build.gradle screenshot as described at Google guide

build Gradle settings

like image 7
Rustam Samandarov Avatar answered Oct 28 '22 03:10

Rustam Samandarov


use this in build.gradle:

    compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true
        // Sets Java compatibility to Java 8
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

dependencies {
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
}
like image 3
Alexei Avatar answered Oct 28 '22 05:10

Alexei