3

I want to subtract 30 minutes from another time string, but I am getting this error on lower versions such as 0.5,0.6,0.7 (Lollipop, Marshmallow, Naught).
Error is as below:

java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/format/DateTimeFormatter;

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
  • 2
    Please post your code block, what you have tried. – Naitik Soni Jul 25 '19 at 13:33
  • Possible duplicate of [Android N Java8 java.time](https://stackoverflow.com/questions/36000997/android-n-java8-java-time) – Ole V.V. Jul 26 '19 at 08:29
  • java.time is built-in from API level 26 (Oreo). There is a backport for lower levels, [ThreeTenABP](https://github.com/JakeWharton/ThreeTenABP). Please consider it. More in this Stack Overflow question: [How to use ThreeTenABP in Android Project](https://stackoverflow.com/questions/38922754/how-to-use-threetenabp-in-android-project). – Ole V.V. Jul 26 '19 at 08:32

1 Answers1

7

I solved this issue by adding these lines in Module level build.gradle file

This happens because of Java.time was added in api level 26 so below 26 throws an error in app.

Just add below lines

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

make sure that multiDexEnabled true in both release and debug

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Arpit Bhoi
  • 96
  • 1
  • 5