Android N Java8 java.time-ThrowExceptions

Exception or error:

I updated to the latest Android N sdk. The only thing I don’t understand is why I cannot import java.time into my code? I thought Java8 is available through Android N. Then why didn’t Google add java.time package?

How to solve:

Android N is not supporting all the features of Java 8.
Following features are only supported:

  • Default and static interface methods
  • Lambda expressions
  • Repeatable annotations

Reflection and language-related APIs:

  • java.lang.FunctionalInterface
  • java.lang.annotation.Repeatable
  • java.lang.reflect.Method.isDefault()

and Reflection APIs associated with repeatable annotations, such as

Utility APIs:

  • java.util.function

For more info check the following link:


There is backport library of java.time APIs for Android that can be used


java.time package was added only in API 26 (Android O):


But, starting with version 4.0 Android Studio allows using a subset of java.time API (along with a number of others Java 8 language APIs), without requiring a minimum API level for your app:

The following set of APIs is supported in this release:

  • Sequential streams (
  • A subset of java.time
  • java.util.function
  • Recent additions to java.util.{Map,Collection,Comparator}
  • Optionals (java.util.Optional, java.util.OptionalInt and java.util.OptionalDouble) and some other new classes useful with the
    above APIs
  • Some additions to java.util.concurrent.atomic (new methods on AtomicInteger, AtomicLong and AtomicReference)
  • ConcurrentHashMap (with bug fixes for Android 5.0)

To enable support for these language APIs, one needs to include the following lines build.gradle file:

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 ''

Leave a Reply

Your email address will not be published. Required fields are marked *