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 {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.0'
    }
}

ℹ️ 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 gradle.properties file.

android.enableDesugar=false

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

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'
    }
}

Android Gradle Plugin 7.4.0

Since AGP 7.4, you can use JavaVersion.VERSION_11 for sourceCompatibility and targetCompatibility.

The kotlinOptions jvmTarget can also be set to '11'.