Java 11+ APIs available through desugaring with the nio specification

Android Studio includes support for using a number of Java 11+ APIs without requiring a minimum API level for your app. This means that if you use an API introduced in Android 13 (API level 33) the code also works on all previous versions. Most APIs introduced to Android over the years are supported on Android 13. Through a process called API desugaring, the DEX compiler (D8) allows you to include more standard language APIs in apps that support older versions of Android.

Java 11 support API desugaring comes in three flavors:

  • The minimal version includes only the java.util.function package and replacement classes for some Android framework concurrent collections that have known issues on old devices.
  • The default version is effectively an upgraded version of the Java 8 API desugaring updated to Java 11. It includes the java.time and java.util.stream packages in addition to everything in the minimal version.
  • The nio version includes the java.nio package in addition to everything in the default version.

The following searchable table shows which Java 11+ libraries are available when you use the latest version of the Android Gradle plugin with the coreLibraryDesugaring dependency set to com.android.tools:desugar_jdk_libs_nio:2.0.1 (see API desugaring for more information). Set this property in the build.gradle or build.gradle.kts file.

Package +
Class,
Enum,
or Interface
Constructors,
Properties,
and Methods
Notes
java.io


 BufferedReader


  • public java.util.stream.Stream lines()

Additional methods on existing class.
 

java.io


 ByteArrayInputStream


  • public long transferTo(OutputStream p0)

Additional methods on existing class.
 

java.io


 File


  • public java.nio.file.Path toPath()

Additional methods on existing class.
 

java.io


 InputStream


  • public long transferTo(OutputStream p0)

Additional methods on existing class.
 

java.io


 UncheckedIOException


  • public UncheckedIOException(IOException cause)
  • public UncheckedIOException(
     String message, IOException cause)
  • public IOException getCause()

Fully implemented class.
 

java.lang


 Character


  • public static boolean isBmpCodePoint(int p0)

Additional methods on existing class.
 

java.lang


 Iterable


  • public void forEach(Consumer action)
  • public java.util.Spliterator spliterator()

Additional methods on existing class.
 

java.net


 URLDecoder


  • public URLDecoder()
  • public static String decode(String s)
  • public static String decode(String s, String enc)
  • public static String decode(
     String s, java.nio.charset.Charset charset)

Fully implemented class.
 

java.net


 URLEncoder


  • public static String encode(String s)
  • public static String encode(String s, String enc)
  • public static String encode(
     String s, java.nio.charset.Charset charset)

Fully implemented class.
 

java.nio.channels
See customizations

 AsynchronousChannel


  • public abstract void close()

Fully implemented class.
 

java.nio.channels
See customizations

 AsynchronousFileChannel


  • protected AsynchronousFileChannel()
  • public abstract void force(boolean p0)
  • public final java.util.concurrent.Future lock()
  • public abstract java.util.concurrent.Future lock(
     long p0, long p1, boolean p2)
  • public abstract void lock(
      long p0,
      long p1,
      boolean p2,
      Object p3,
      CompletionHandler p4)
  • public final void lock(
     Object attachment, CompletionHandler handler)
  • public static AsynchronousFileChannel open(
      Path file,
      java.util.Set options,
      java.util.concurrent.ExecutorService executor,
      FileAttribute[] attrs)
  • public static AsynchronousFileChannel open(
     Path file, OpenOption[] options)
  • public abstract java.util.concurrent.Future read(
     ByteBuffer p0, long p1)
  • public abstract void read(
      ByteBuffer p0,
      long p1,
      Object p2,
      CompletionHandler p3)
  • public abstract long size()
  • public abstract AsynchronousFileChannel truncate(
     long p0)
  • public final FileLock tryLock()
  • public abstract FileLock tryLock(
     long p0, long p1, boolean p2)
  • public abstract java.util.concurrent.Future write(
     ByteBuffer p0, long p1)
  • public abstract void write(
      ByteBuffer p0,
      long p1,
      Object p2,
      CompletionHandler p3)

Fully implemented class.
 

java.nio.channels
See customizations

 CompletionHandler


  • public abstract void completed(Object p0, Object p1)
  • public abstract void failed(Throwable p0, Object p1)

Fully implemented class.
 

java.nio.channels
See customizations

 FileChannel


  • public static FileChannel open(
      Path path,
      java.util.Set options,
      FileAttribute[] attrs)
  • public static FileChannel open(
     Path path, OpenOption[] options)

Additional methods on existing class.
 

java.nio.channels
See customizations

 SeekableByteChannel


  • public abstract long position()
  • public abstract SeekableByteChannel position(
     long p0)
  • public abstract int read(ByteBuffer p0)
  • public abstract long size()
  • public abstract SeekableByteChannel truncate(
     long p0)
  • public abstract int write(ByteBuffer p0)

Fully implemented class.
 

java.nio.charset
See customizations

 StandardCharsets


  • public static final Charset ISO_8859_1
  • public static final Charset US_ASCII
  • public static final Charset UTF_16
  • public static final Charset UTF_16BE
  • public static final Charset UTF_16LE
  • public static final Charset UTF_