Support JAVA-8 Jar in Android 5 - React Native

591 views Asked by At

Solution from Android Documentation is below

  android {
  defaultConfig {
    // Required when setting minSdkVersion to 20 or lower
    multiDexEnabled true
  }

  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.0.9'
}

This is working fine for Native android app, But this configuration is not working for React-Native app and throwing below error while building the app.

A problem occurred evaluating project ':app'.

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

1

There are 1 answers

0
u_pendra On

Half knowledge in always dangerous, and it happens here. As per the documentation above solution worked only for gradle version greater than 4. My gradle version was

classpath("com.android.tools.build:gradle:3.5.3")

I changed it to

classpath "com.android.tools.build:gradle:4.0.1"

Now it's working.