18

I need to use method setStartTimestamp(OffsetDateTime startTimestamp) but my minSdk is 21 so it shows me Call requires API level 26. Is there any way how can I use OffsetDateTime on lower apis?

Martin
  • 642
  • 9
  • 26

2 Answers2

11

You can use Java 8+ API desugaring support (Android Gradle Plugin 4.0.0+)

It is described in this link

Simply you have to modify your build.gradle file in your app module like this:

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'
}
M.Kasaei
  • 188
  • 5
  • 12
9

java.time APIs on Android require API 26.

For older API levels you can use ThreeTenABP which is the Android version of JSR-310 java.time backport for Java 6.

laalto
  • 144,748
  • 64
  • 275
  • 293