简体   繁体   中英

Support JAVA-8 Jar in Android 5 - React Native

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM