Java 8 Source Compatibility

PSPDFKit library started using Java 8 language features in version 5.

Java 8 has been supported natively since Android SDK 26 and Android Studio 3.0. If your minimal SDK version is lower than 26, .class files produced by the javac compiler need to be converted to bytecode that is supported by these SDK versions. This process is called desugaring. You’ll still need to update to Android Studio 3.0 or later for full Java 8 support in your IDE.

PSPDFKit, similar to other third-party libraries, ships with .class files that are not yet desugared. The desugaring process has been supported since Android Gradle plugin 3.0.0 and runs only when your application also uses Java 8. This means that in order to integrate PSPDFKit 5 into your application that is using a minimum SDK version lower than 26, you’ll need to perform the following steps.

  1. Update your Android Gradle plugin to version 3.0.0 or higher:

buildscript {
    repositories {
    dependencies {
        classpath ''
  1. Change Source Compatibility and Target Compatibility for each module that uses PSPDFKit to 1.8:

android {
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8

ℹ️ Note: Desugaring is enabled by default when using Android Gradle plugin version 3.0.0 or higher. However, it can be disabled with the following property in your file.


Please make sure to remove this property or set it to true to enable desugaring.

Dexing Error Messages

You should look for the following error messages after updating to PSPDFKit 5 or above. All of these can be fixed by enabling desugaring for PSPDFKit via the steps outlined above:

D8: Invoke-customs are only supported starting with Android O (--min-api 26)
Caused by: Error while dexing.
The dependency contains Java 8 bytecode. Please enable desugaring by adding the following to build.gradle
android {
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
See for details. Alternatively, increase the minSdkVersion to 26 or above.

Kotlin and Java 8

By default, the Kotlin compiler targets Java 6. This means that if you are using Java 8 source compatibility in your Java code, you can’t use certain features, like calling to default interfaces of Java classes, in your Kotlin code.

If you wish to enable full Java 8 support inside your Kotlin code, add the following snippet to your build.gradle file:

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8

    kotlinOptions {
        jvmTarget = '1.8'