user149408
user149408

Reputation: 5901

NoClassDefFoundError when using java.time on Android

My Android app uses a JAR which relies on a few classes from java.time, such as LocalTime, and therefore requires at least Java 8.

Several sources on the net point out that later versions of Android and the tool chain support Java 8.

I build my app with gradle but do not use (or wish to use) Android Studio. I use version 3.1.4 of the plugin (the latest which is compatible with Gradle 4.4, the version that ships with the latest LTS of Ubuntu, 18.04 as of this writing). Minimum SDK is 14, target is 26. Build tools version is 27.0.3.

The app builds and installs fine, but when it tries to use one of the classes, it crashes with an exception:

Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/LocalTime;

Questions:

Upvotes: 2

Views: 283

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007296

Is java.time available on Android versions with Java 8 support?

Yes.

If so, what is the minimum API version?

LocalDateTime is available on API Level 26 and higher, as is noted in the JavaDocs (see upper-right corner).

Anything else I am missing?

You might consider using a backport of the Java 8 date/time APIs.

Upvotes: 5

Related Questions