Call requires API level 26 (current min is 23): java.time.Instant#now

If you're using Gradle plugin 4.0 or later (with Android Studio 4.0 or later), you can take advantage of D8 Core Library Desugaring. This includes a subset of the functionality found in java.time and will allow you to use java.time.Instant in your project; even if you need to support versions older than API 26.

In your module's build.gradle file:

android {

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
        coreLibraryDesugaringEnabled true
    }

    // If using Kotlin
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }
}
dependencies {
    …
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.5'
}

You should now be able to use this class error free.

Some sources:

  • Styling Android
  • Jake Wharton
  • Android Developers

After reviewing the developer guide, it turned out that either String now,

as well as common int UNIX epoch timestamps, are being acceptable values:

departure_time — Specifies the desired time of departure. You can specify the time as an integer in seconds since midnight, January 1, 1970 UTC. Alternatively, you can specify a value of now, which sets the departure time to the current time (correct to the nearest second).

When checking the source code of the Java client, there is a convenience method for that:

public DirectionsApiRequest departureTimeNow() {
    return param("departure_time", "now");
}

Therefore java.time.Instant can be circumvented, for the backwards compatibility.


I've filed issue #559... forking the library seems to be the only way to set other timestamps.