PSPDFKit 2.8 Migration Guide

This guide covers migrating to PSPDFKit 2.8 for React Native, which requires changes to move to Gradle 8.

Initializing the PSPDFKit Plugin

Information

Customers who are using their application in production and have already set their license keys aren’t affected by this change.

PSPDFKit for React Native 2.8 now requires you to initialize the PSPDFKit plugin, even when running in trial mode. The plugin is initialized by calling either the setLicenseKey or setLicenseKeys API when your application starts. In your main .ts or .js file, add the following above your class declaration:

import { NativeModules } from 'react-native';
...
const PSPDFKit = NativeModules.PSPDFKit;
PSPDFKit.setLicenseKey(null);

iOS CocoaPods Dependencies

PSPDFKit now specifies the iOS versions of the PSPDFKit and Instant SDKs as part of the plugin source code, and it no longer needs to be set in your application Podfile.

If present, remove the PSPDFKit and Instant entries from ios/Podfile:

-  pod "PSPDFKit", podspec: "https://customers.pspdfkit.com/pspdfkit-ios/latest.podspec"
-  pod "Instant", podspec: "https://customers.pspdfkit.com/instant/latest.podspec"

Next, delete Podfile.lock and run pod install from within your project’s ios directory:

pod install

Bumping the Android compileSdkVersion

To continue to bring our customers the latest features offered by our native SDKs, we depend on the latest PSPDFKit Android SDK. When you upgrade to PSPDFKit 2.8 for React Native, your application’s compileSdkVersion needs to be set to a minimum of 34.

To change the compileSdkVersion of your Android module, open your module’s app-level Gradle file in your_project_folder/android/app/build.gradle, and set compileSdkVersion as shown below:

android {
    ...
    compileSdkVersion 34
    ...
}
Information

Some projects may be using Gradle extra properties (ext) to store the version number in a separate .gradle file. In this case, update the value of the compileSdkVersion property. Refer to our example Catalog for more details.

Upgrade Gradle

The PSPDFKit Android SDK, on which the React Native plugin depends, requires your Gradle version to be upgraded to 8. Even though the newly released React Native 0.73 also requires Gradle 8, some React Native dependencies aren’t yet supported. Please check the various dependency home pages to ensure you’re running a version that supports Gradle 8. To upgrade, make the changes outlined below.

In your_project_folder/android/build.gradle, change your Gradle version to 8.1.0:

dependencies {
  classpath('com.android.tools.build:gradle:8.1.0')
}

Then, update your_project_folder/android/gradle/wrapper/gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
- distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
+ distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Alternatively, you can open the android module of your project in the current stable Android Studio, and Android Studio will suggest an automatic Gradle update using AGP Upgrade Assistant.

After upgrading to Gradle 8, you’ll be required to update your JDK version to Java 17, which is supported by Gradle 8. After downloading and installing the Java 17 JDK, ensure your JAVA_HOME environment variable in your ~/.zshrc or ~/.bash_profile is configured to point to the new JDK location.