How to fix "Call requires API level 26 (current min is 25) " error in Android
The best way to use LocalDateTime
on a lower versions of Android is by desugaring (you must have Android Gradle plugin version 4.0 or higher). Just add the below lines to your app
module gradle file:
Finally, add the ff. dependency to your dependencies block:
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'
You need to use https://github.com/JakeWharton/ThreeTenABP to be able using LocalDateTime with Android API < 26.
Add the dependencies to your project (please follow the project README):
implementation 'com.jakewharton.threetenabp:threetenabp:1.2.1'
Then change your LocalDateTime
import from:
import java.time.LocalDateTime;
to:
import org.threeten.bp.LocalDateTime;
Update:
The library mentioned above is no longer the best way as mentioned in JakeWharton/ThreeTenABP README:
Attention: Development on this library is winding down. Please consider switching to Android Gradle plugin 4.0, java.time.*, and its core library desugaring feature in the coming months.
To use LocalDateTime
in older API levels, use the desugaring feature from Gradle plugin 4.0:
https://developer.android.com/studio/write/java8-support#library-desugaring